Edit report at http://bugs.php.net/bug.php?id=51886&edit=1

 ID:               51886
 Comment by:       boldin dot pavel at gmail dot com
 Reported by:      vesko at webstudiobulgaria dot com
 Summary:          call_user_func() does not propagate the scope
 Status:           Open
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Debian 5.0
 PHP Version:      5.3SVN-2010-05-22 (snap)

 New Comment:

Simple patch attached. Works, but can cause side effects.


Previous Comments:
------------------------------------------------------------------------
[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] m...@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 http://bugs.php.net/bug.php?id=51886&edit=1

Reply via email to