php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47402 call_user_func propagating the scope while it didn't in 5_2
Submitted: 2009-02-16 10:33 UTC Modified: 2009-02-24 01:00 UTC
From: colder@php.net Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: 5.3.0beta1 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: colder@php.net
New email:
PHP Version: OS:

 

 [2009-02-16 10:33 UTC] colder@php.net
Description:
------------
Depending on the context and the callback, call_user_func didn't propagate $this in 5_2. It now does in 5_3. Not sure which one is more correct, but there is definitely a potential BC break here.

Reproduce code:
---------------
<?php
class A {
    public function test() {
        B::foo();
        call_user_func(array("B", "foo"));
    }

}

class B extends A {
    public function foo() {
        var_dump($this);
    }
}

$b = new B; $b->test();

?>

Expected result:
----------------
// 5_2's output
object(B)#1 (0) {
}
NULL

Actual result:
--------------
// 5_3's output
object(B)#1 (0) {
}
object(B)#1 (0) {
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-16 16:25 UTC] dmitry@php.net
This is not a bug, but just an illustration of is_callable/call_user_func mess which was fixed in 5.3 comparing to 5.2. The following extended example illustrates inconsistent behaviour of 5.2. Using call_user_func() it passes $this in one case and not in the other, however direct call passes %this in both cases.

<?php
class A {
    public function test() {
        B::foo();
        call_user_func(array("B","foo"));
    }
    public function bar() {
        var_dump($this);
    }
}

class B extends A {
    public function foo() {
        var_dump($this);
    }
    public function test2() {
        A::bar();
        call_user_func(array("A","bar"));
    }
}

$b = new B; $b->test(); $b->test2();
?>

PHP-5.2
-------
object(B)#1 (0) {
}
NULL
object(B)#1 (0) {
}
object(B)#1 (0) {
}

PHP-5.3
-------
object(B)#1 (0) {
}
object(B)#1 (0) {
}
object(B)#1 (0) {
}
object(B)#1 (0) {
}

 [2009-02-16 22:35 UTC] colder@php.net
Ok then, if this is intended, it should probably get mentionned in 5_2->5_3 migration guide, I just added it to the scratchpad and reclassify as documentation problem so it's not forgotten.
 [2009-02-24 01:00 UTC] doc-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 04:01:29 2024 UTC