Bug #66719 [Ver->Csd]: Weird behaviour when using get_called_class() with call_user_func()

From: Date: Fri, 23 Jul 2021 09:25:35 +0000
Subject: Bug #66719 [Ver->Csd]: Weird behaviour when using get_called_class() with call_user_func()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235291@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66719&edit=1 ID: 66719 Updated by: git@php.net Reported by: coolwust at gmail dot com Summary: Weird behaviour when using get_called_class() with call_user_func() -Status: Verified +Status: Closed Type: Bug Package: Class/Object related Operating System: linux PHP Version: 5.5.9 Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikic Revision: https://github.com/php/php-src/commit/dfd05da97f72628c5124bfb54976d2c3a02dba82 Log: Fix bug #66719 Previous Comments: ------------------------------------------------------------------------ [2021-07-23 08:39:32] nikic@php.net This even causes an assertion failure nowadays: php: /home/nikic/php/php-src/Zend/zend_vm_execute.h:35335: ZEND_GET_CALLED_CLASS_SPEC_UNUSED_UNUSED_HANDLER: Assertion `!((execute_data)->func)->common.scope' failed. ------------------------------------------------------------------------ [2015-08-18 18:05:31] cmb@php.net The example calls this feature "relative static class method call", and as such it should behave identically to calling A::who() directly, but it doesn't: <https://3v4l.org/vbuVd>. Interestingly, calling the callable $method directly fails completely. ------------------------------------------------------------------------ [2014-02-16 01:41:22] coolwust at gmail dot com 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" ------------------------------------------------------------------------ [2014-02-16 01:27:01] coolwust at gmail dot com I was thinking it should output B, but yea, you are right, it simply means B's parent who, but doesn't mention the calling scope. The documentation should show more details on parent::who, what exactly it means. ------------------------------------------------------------------------ [2014-02-16 00:00:57] requinix@php.net Interesting. I had no idea that feature existed. Just checked with 5.5.6 and it has the same behavior. Looks like a bug then as it's not showing any class at all. However I'm not sure which class it should show: could be A if it resolved as B::parent's who, or it could be B if it resolved as B and then parent::who. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=66719 -- Edit this bug report at https://bugs.php.net/bug.php?id=66719&edit=1

« previous php.bugs (#235291) next »