|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69747 recursive invocation of call_user_func loses object state
Submitted: 2015-06-02 14:55 UTC Modified: 2018-07-27 14:57 UTC
From: remyfox at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.6.9 OS: Windows 8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: remyfox at hotmail dot com
New email:
PHP Version: OS:


 [2015-06-02 14:55 UTC] remyfox at hotmail dot com
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:

	class A {
		private function z() {
			echo __METHOD__;
		public function x() {
			$callback = [[new $this(), "z"], []];
	(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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-05 23:07 UTC]
FWIW: this issue is already fixed in master, see
<>. I'm not sure whether it should be
 [2018-07-27 14:57 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-07-27 14:57 UTC]
Fixed in all actively supported versions.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 16:01:28 2024 UTC