|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-02-15 18:28 UTC] coolwust at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/function.get-called-class --- B::who(); should has the same result as call_user_func(array('B', 'parent::who')); But it's not. See the example below. Test script: --------------- <?php class A { public static function who() { var_dump(get_called_class()); } } class B extends A { public static function who() { parent::who(); } } B::who(); call_user_func(array('B', 'parent::who')); ?> Expected result: ---------------- string 'B' (length=1) string 'B' (length=1) Actual result: -------------- string 'B' (length=1) boolean false PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 05:00:02 2025 UTC |
array('B', 'parent::who') is not valid: the second element must be the name of a method. array('B', 'who') is the correct form.here is a new little test snippet: class A { public static function who() { $obj = new static; var_dump($obj); } } class B extends A { public static function who() { parent::who(); } } B::who(); //output object(B)[1] call_user_func(array('B', 'parent::who')); //output Fatal error: Cannot access static:: when no class scope is active This means get_called_class() does it job correctly, as it is out of scope and returns null. However, the doc should gives more details on "parent::who"