Bug #51886 [Opn->Wfx]: call_user_func() does not propagate the scope
| From: | nikic@php.net | Date: | Fri, 06 May 2016 14:22:20 +0000 |
| Subject: | Bug #51886 [Opn->Wfx]: call_user_func() does not propagate the scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200925@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51886&edit=1
ID: 51886
Updated by: nikic@php.net
Reported by: vesko at webstudiobulgaria dot com
Summary: call_user_func() does not propagate the scope
-Status: Open
+Status: Wont fix
Type: Bug
Package: Scripting Engine problem
Operating System: Debian 5.0
PHP Version: 5.3SVN-2010-05-22 (snap)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-06-08 10:54:48] boldin dot pavel at gmail dot com
Simple patch attached. Works, but can cause side effects.
------------------------------------------------------------------------
[2010-05-25 09:58:16] 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-05-25 09:06:41] mike@php.net
doh! From my understanding, this should say "no" *all* 4 times. There's no t2
instance.
------------------------------------------------------------------------
[2010-05-22 16:10:50] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51886&edit=1