php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64914 get_called_class incorrect after call_user_func to a parent static function
Submitted: 2013-05-24 08:15 UTC Modified: 2020-10-19 09:25 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: e dot nash at dvz-mv dot de Assigned:
Status: Verified Package: Class/Object related
PHP Version: 5.4.15 OS: Win/Linux
Private report: No CVE-ID: None
 [2013-05-24 08:15 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-24 09:24 UTC] 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.
 [2018-07-11 20:10 UTC] dev at mike dot pp dot ua
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().
 [2020-10-19 09:25 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-10-19 09:25 UTC] cmb@php.net
Confirmed: <https://3v4l.org/hscB8>.

It seems to me that CUF/CUFA needed to use the calling scope of
the passed callable instead of the called scope.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC