Jump to content

Initialize a sub-class into a class

- - - - -

  • Please log in to reply
No replies to this topic

#1
bobalazek124

bobalazek124

    Newbie

  • Members
  • Pip
  • 1 posts
Hey, I have a problem. I know the problem is really simple, I don't know to solve it.

OK, I write a simple PHP engine. I have a main class, called engine_class.php in the root, and sub classes in a subfolder called plugins. I've already wrote a autoloader etc, but here comes the problem.

The "engine_class.php":



// Autoloader ..


class engine {


// Declarations, functions, etc...


function __call ($name, $args) {


$this->$name = new $name;


return call_user_func_array(array($this->$name, $name), $args);


}


}


(I've already created some sub-classes... cookie, mysql...)

Now i want, in example (index.php):


include "engine_class.php";


$engine = new engine;


// static

$engine->cookie()::set("name", "value"); // I know that this don't work


// or non-static

$engine->mysql("localhost", "test", "test", "test");


$engine->mysql()->query("SELECT * FROM test");


Now, how can I do, that my sub-classes wil work like in my upper example in/with the main class?

So, that i can use it like this:

$engine = new engine;


$engine->[subclass]()->[submethod]($arg1, $arg2, ...);

// or for static:

$engine->[subclass]()::[submethod]($arg1, $arg2, ...);






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users