Bug #69747 [NEW]: recursive invocation of call_user_func loses object state
| From: | remyfox at hotmail dot com | Date: | Tue, 02 Jun 2015 14:55:22 +0000 |
| Subject: | Bug #69747 [NEW]: recursive invocation of call_user_func loses object state | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193073@lists.php.net to get a copy of this message | ||
From: remyfox at hotmail dot com
Operating system: Windows 8
PHP version: 5.6.9
Package: Unknown/Other Function
Bug Type: Bug
Bug description:recursive invocation of call_user_func loses object state
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 bug report at https://bugs.php.net/bug.php?id=69747&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69747&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69747&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69747&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69747&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69747&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69747&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69747&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69747&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69747&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69747&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69747&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69747&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69747&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69747&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69747&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69747&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69747&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69747&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69747&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69747&r=mysqlcfg