php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51886 call_user_func() does not propagate the scope
Submitted: 2010-05-22 16:10 UTC Modified: 2016-05-06 14:22 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: vesko at webstudiobulgaria dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3SVN-2010-05-22 (snap) OS: Debian 5.0
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-05-22 16:10 UTC] vesko at webstudiobulgaria dot com
Description:
------------
call_user_func() does not propagate the scope when used in calls between two classes that have no child-parent relation. When they have child-parent relation as described in this bug entry: http://bugs.php.net/bug.php?id=47402 it is fine.

As it is put in the "Backward Incompatible Changes" here:
http://www.php.net/manual/en/migration53.incompatible.php
"The call_user_func() family of functions now propagate $this even if the callee is a parent class. ". I guess it has to do it for classes that have no relation as well (or if not so the direct call t2::some_method() should not do it either). As it is at the moment is inconsistent.

P.S. As well I think a better explanation with an example in the docs should be added for "The call_user_func() family of functions now propagate $this even if the callee is a parent class.". It is not clear at all what it is about if one don't get onto the original bug entry: "http://bugs.php.net/bug.php?id=47402".
I didnt use the original 47402 entry as in fact it is not a bug.

Test script:
---------------
class t1
{
	public function __call($method,$args) {
		//call_user_func('t2::some_method',$args);//for PHP 5.3
		call_user_func(array('t2','some_method'),$args);
		t2::some_method();
	}
	
	public function existing_method() {
		//call_user_func('t2::some_method');//for PHP 5.3
		call_user_func(array('t2','some_method'));
		t2::some_method();
	}
}

class t2
{
	public function some_method() {
		print isset($this)?'yes':'no';
		print PHP_EOL;
	}
}

$t1 = new t1;

$t1->existing_method();
$t1->non_existing_method();//use overloading

Expected result:
----------------
yes
yes
yes
yes


Actual result:
--------------
no
yes
no
yes

Patches

remove-inheritance-check-at-call-2.patch (last revision 2010-06-08 09:01 UTC by boldin dot pavel at gmail dot com)
remove-inheritance-check-at-call.patch (last revision 2010-06-08 04:54 UTC by boldin dot pavel at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-25 09:06 UTC] mike@php.net
doh! From my understanding, this should say "no" *all* 4 times. There's no t2 instance.
 [2010-05-25 09:58 UTC] vesko at webstudiobulgaria dot com
well, yes or no it has to be consistent. My personal opinion is also that $this should not be defined, but as I quoted it above according PHP 5.3 policy it should say yes.
 [2010-06-08 10:54 UTC] boldin dot pavel at gmail dot com
Simple patch attached. Works, but can cause side effects.
 [2016-05-06 14:22 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2016-05-06 14:22 UTC] nikic@php.net
Closing this as "Won't Fix" because:
 * On PHP 7.0 we no longer adopt incompatible $this contexts, so the result is "no" for all cases.
 * On PHP 5.6 we *could* fix this. However given that the behavior is on the way out anyway, I don't think we should change this in a direction that goes contrary to what PHP 7 does. This would mean that we have one behavior from PHP 5.0 to PHP 5.6.N, another from PHP 5.6.N+1 to PHP 5.6.M and then again the old behavior in PHP 7.0, which is a bad spot to be in.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC