Edit report at https://bugs.php.net/bug.php?id=65828&edit=1
ID: 65828 Updated by: ras...@php.net Reported by: stefaan at netlog dot com Summary: parent::X() triggers child's __call('X'), instead of parent's __call('X') -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: OSX, Ubuntu PHP Version: 5.4.20 Block user comment: N Private report: N New Comment: That's how classes are composed. There is no bug here. CCC:__call() is the active __call() method for this instance no matter where in the hierarchy you are. You can explicitly call other versions of methods via lsb, of course. See http://php.net/lsb Previous Comments: ------------------------------------------------------------------------ [2013-10-03 16:02:38] stefaan at netlog dot com Description: ------------ In the code example below the parent::getX() call in BB::getX() resolves to CCC:__call('X') instead of to A:__call('X'), which I would expect. It seems weird that "parent" in BB:getX() resolves to CCC, which is not the parent of BB (it's vice versa) nor CCC. I get this behavior on PHP 5.3.26, but also PHP 5.4.20 Test script: --------------- class A { public function whoami() { return 'A'; } public function __call($method, array $args) { return 'A::__call::' . $method; } } class BB extends A { public function whoami() { return 'BB'; } public function getX() { return 'BB::getX (FYI: parent is ' . parent::whoami(). ') -> ' . parent::getX() ; } } class CCC extends BB { public function whoami() { return 'CCC'; } public function __call($method, array $args) { return 'CCC::__call::' . $method . ' -> ' . parent::__call($method, $args); } } $c = new CCC(); echo $c->getX() . "\n"; Expected result: ---------------- BB::getX (FYI: parent is A) -> A::__call::getX Actual result: -------------- BB::getX (FYI: parent is A) -> CCC::__call::getX -> A::__call::getX ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65828&edit=1