Bug #77877 [Com]: call_user_func() passes $this to static methods

From: Date: Thu, 11 Apr 2019 11:32:33 +0000
Subject: Bug #77877 [Com]: call_user_func() passes $this to static methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220401@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77877&edit=1 ID: 77877 Comment by: me at mega6382 dot me Reported by: dmitry@php.net Summary: call_user_func() passes $this to static methods Status: Closed Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 7.1Git-2019-04-11 (Git) Assigned To: dmitry Block user comment: N Private report: N New Comment: To me this seems to be: call_user_func([new Foo, 'bar']); Equivalent to: $obj = new Foo; $obj->bar(); 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: Foo::Bar(); It performs static call. which I think how is it should be. Previous Comments: ------------------------------------------------------------------------ [2019-04-11 11:31:51] dmitry@php.net Automatic comment on behalf of dmitry@zend.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=a1b7ccdfc69a1ad9938039f687ad7059ed1bd506 Log: Fixed bug #77877 (call_user_func() passes $this to satatic methods). ------------------------------------------------------------------------ [2019-04-11 10:34:15] dmitry@php.net Description: ------------ 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: --------------- <?php class Foo { static public function bar() { var_dump($this); } } 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) { } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77877&edit=1

« previous php.bugs (#220401) next »