Bug #64914 [Com]: get_called_class incorrect after call_user_func to a parent static function
| From: | e dot nash at dvz-mv dot de | Date: | Fri, 24 May 2013 09:24:44 +0000 |
| Subject: | Bug #64914 [Com]: get_called_class incorrect after call_user_func to a parent static function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179112@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64914&edit=1
ID: 64914
Comment by: e dot nash at dvz-mv dot de
Reported by: e dot nash at dvz-mv dot de
Summary: get_called_class incorrect after call_user_func to a
parent static function
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Win/Linux
PHP Version: 5.4.15
Block user comment: N
Private report: N
New Comment:
Forgot to add:
static::test() in both runStatic() and run() produces the output C, as would be expected through the
LSB.
Previous Comments:
------------------------------------------------------------------------
[2013-05-24 08:15:28] e dot nash at dvz-mv dot de
Description:
------------
When called from an instance function via call_user_func (or call_user_func_array), the late static
binding appears to not recognise an explicit call to a parent static function and propagates the
caller as the called class rather than the callee.
When called "directly" the late static binding functions correctly.
To reiterate: there is an inconsistency here between the results with P::test() and
call_user_func('P::test') in the test script below. My opinion is that this is a bug.
Tested with the script below in PHP 5.3 and PHP 5.4.15.
If this is the expected behaviour ("feature not a bug") then it should be prominently
documented (c.f. bug #47402)
Test script:
---------------
abstract class P {
static public function test() {
echo get_called_class();
}
}
class C extends P {
public static function runStatic() {
P::test();
call_user_func('P::test');
call_user_func(array('P', 'test'));
}
public function run() {
P::test();
call_user_func('P::test');
call_user_func(array('P', 'test'));
}
}
C::runStatic();
$c = new C();
$c->run();
Expected result:
----------------
Console output:
PPPPPP
Actual result:
--------------
Console output:
PPPPCC
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64914&edit=1