Bug #64914 [Com]: get_called_class incorrect after call_user_func to a parent static function

From: Date: Wed, 11 Jul 2018 20:10:57 +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-216280@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: dev at mike dot pp dot ua 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: Still not fixed in PHP 7.2.7-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:45:49) ( NTS ). Seems like the call_user_func() (and call_user_func_array()) works the same way as the forward_static_call(). Previous Comments: ------------------------------------------------------------------------ [2013-05-24 09:24:44] e dot nash at dvz-mv dot de Forgot to add: static::test() in both runStatic() and run() produces the output C, as would be expected through the LSB. ------------------------------------------------------------------------ [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

« previous php.bugs (#216280) next »