Bug #69747 [Opn]: recursive invocation of call_user_func loses object state

From: Date: Fri, 05 Jun 2015 23:07:23 +0000
Subject: Bug #69747 [Opn]: recursive invocation of call_user_func loses object state
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193160@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69747&edit=1 ID: 69747 Updated by: cmb@php.net Reported by: remyfox at hotmail dot com Summary: recursive invocation of call_user_func loses object state Status: Open Type: Bug Package: Unknown/Other Function Operating System: Windows 8 PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: FWIW: this issue is already fixed in master, see <http://3v4l.org/gAkh8>. I'm not sure whether it should be back-ported. Previous Comments: ------------------------------------------------------------------------ [2015-06-02 14:55:22] remyfox at hotmail dot com Description: ------------ Calling call_user_func(_array) more than one level deep will no longer take into account the callback object's state. E.g. call_user_func("call_user_func", $callback); I am not entirely certain this is a bug: after all, usually once a function is called, an object's environment is left. However, call_user_func seems to be the exception to this rule, because the function would lose its significance otherwise. Test script: --------------- Anyway, class A { private function z() { echo __METHOD__; } public function x() { $callback = [[new $this(), "z"], []]; $callback[0](...$callback[1]); } } (new A())->x(); // This works fine and can be rewritten to: class A { private function z() { echo __METHOD__; } public function x() { $callback = [[new $this(), "z"], []]; call_user_func_array("call_user_func_array", $callback); } } (new A())->x(); Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method A::z() in FILE. Expected result: ---------------- Stacked invocation of call_user_func(_array) should not leave the callback object's state. Actual result: -------------- Stacked invocation of call_user_func(_array) leaves the callback object's state. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69747&edit=1

« previous php.bugs (#193160) next »