|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77877 call_user_func() passes $this to static methods
Submitted: 2019-04-11 10:34 UTC Modified: 2019-04-11 18:23 UTC
From: Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1Git-2019-04-11 (Git) OS: *
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:
Solve the problem:
11 + 4 = ?
Subscribe to this entry?

 [2019-04-11 10:34 UTC]
call_user_func([$obj,"static_method"]) actually performs non-static call.

Most other internal functions that use callbacks (e.g. array_map) are not affected.

Test script:
class Foo {
        static public function bar() {
try {
        array_map([new Foo, 'bar'],[1]);
} catch (Throwable $e) {
        echo $e->getMessage() . "\n";
try {
        call_user_func([new Foo, 'bar']);
} catch (Throwable $e) {
        echo $e->getMessage() . "\n";

Expected result:
Using $this when not in object context
Using $this when not in object context

Actual result:
Using $this when not in object context
object(Foo)#3 (0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-11 10:34 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2019-04-11 10:53 UTC]
-Summary: call_user_func() passes $this to satatic methods +Summary: call_user_func() passes $this to static methods
 [2019-04-11 11:31 UTC]
Automatic comment on behalf of
Log: Fixed bug #77877 (call_user_func() passes $this to satatic methods).
 [2019-04-11 11:31 UTC]
-Status: Assigned +Status: Closed
 [2019-04-11 11:32 UTC] me at mega6382 dot me
To me this seems to be:

call_user_func([new Foo, 'bar']);

Equivalent to:

$obj = new Foo;

Both of these performs non-static call, which I think is how it should be. 

But if you write it like this:

call_user_func(['Foo', 'bar']);

which is equivalent to:


It performs static call. which I think how is it should be.
 [2019-04-11 18:23 UTC]
If bar() declared as static, the following code makes a static call.

$obj = new Foo;

call_user_func() was fixed to do the same.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun May 09 05:01:23 2021 UTC