php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 - 19 = ?
Subscribe to this entry?

 
 [2015-06-02 14:55 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-05 23:07 UTC] cmb@php.net
FWIW: this issue is already fixed in master, see
<http://3v4l.org/gAkh8>. I'm not sure whether it should be
back-ported.
 [2018-07-27 14:57 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-07-27 14:57 UTC] cmb@php.net
Fixed in all actively supported versions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC