Answer the question
In order to leave comments, you need to log in
How to implement class inheritance in PHP like in PHALCON?
Good day. Please help find a solution.
There is a class:
class Module {
public function share($moduleName, $func) {
$this->$moduleName = $func();
}
}
$module = new Module();
$module->share('router', function(){
return new Router();
});
$module->share('acl', function(){
return new ACL();
});
Answer the question
In order to leave comments, you need to log in
Sounds like a misnomer for "inherit".
You create an instance of a class, store some values in the resulting object, and you want... what?
So that all instances of this class receive these properties? Then you need to put the code that calls the method share()
into the class constructor.
Just make another instance of the class that has the same properties? I have no idea why you need this, but you can do it.
If you want a new class that will have these properties, inherit from the current class, and write the "sharing" code in the constructor of the new child class.
If all these options are past - specify what exactly you need to get as a result. $newModule = clone $module;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question