Edit report at https://bugs.php.net/bug.php?id=65828&edit=1
ID: 65828
User updated by: stefaan at netlog dot com
Reported by: stefaan at netlog dot com
Summary: parent::X() triggers child's __call('X'), instead of
parent's __call('X')
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:
Thanks for the quick response.
So to get this straight, if I understood you correctly:
in BB::getX():
the call parent::getX() resolves to something like
"method A::getX() called on a CCC instance"
which does not exists and triggers
__call('getX') on the CCC instance, so CCC::__call('getX')
I'm not sure I understood your comment on LSB.
>From the test script I learn that "parent::" is "non-LSB" like "self::", but
>there does not exist a LSB equivalent of "parent::", right? So there is no
>other option here. (And if there would be, it would result in an endless loop
>in this case.)
Previous Comments:
------------------------------------------------------------------------
[2013-10-03 17:46:15] [email protected]
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
------------------------------------------------------------------------
[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