PHP: Access Method in sub-class -
i want know how access method sub-class of class when i'm in sub-class of same class... example:
class foo { } class bar extends foo { public function something() { //do here } } class soap extends foo { $this->something(); //this method wanna call... } as can see wanna access subclass's method sub class. how do in php?
you can directly, if soap subclass of bar:
class soap extends bar { public function somefunction() { $this->something(); // work } } if it's not, still have option: obtain instance of bar , call method on it:
class soap extends foo { public function somefunction(bar $bar) { $bar->something(); // work } } barring that, there's not else can do. since bar not in soap's inheritance chain, there no way reference something using $this within of soap's methods.
Comments
Post a Comment