]> granicus.if.org Git - php/commitdiff
Fixed bug #77877 (call_user_func() passes $this to satatic methods).
authorDmitry Stogov <dmitry@zend.com>
Thu, 11 Apr 2019 11:24:04 +0000 (14:24 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 11 Apr 2019 11:24:04 +0000 (14:24 +0300)
NEWS
Zend/tests/bug77877.phpt [new file with mode: 0644]
Zend/zend_API.c

diff --git a/NEWS b/NEWS
index 178b551273bf430b233f50d3b3b8c40b4e6e3541..faa1c164b4f003aadff79812671324ae57f36276 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP                                                                        NEWS
 - Core:
   . Fixed bug #77345 (Stack Overflow caused by circular reference in garbage
     collection). (Alexandru Patranescu, Nikita, Dmitry)
+  . Fixed bug #77877 (call_user_func() passes $this to satatic methods).
+    (Dmitry)
   . Implemented request #76148 (Add array_key_exists() to the list of
     specially compiled functions). (Majkl578)
   . Fixed bug #76430 (__METHOD__ inconsistent outside of method).
diff --git a/Zend/tests/bug77877.phpt b/Zend/tests/bug77877.phpt
new file mode 100644 (file)
index 0000000..9e0181e
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #77877 call_user_func() passes $this to satatic methods
+--FILE--
+<?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";
+}
+?>
+--EXPECT--
+Using $this when not in object context
+Using $this when not in object context
index 881ee27a031e699a77a87c4044622952576b7383..20b5fbb3b476745643d1d3d6cc573baa0faab9eb 100644 (file)
@@ -3170,6 +3170,10 @@ get_function_via_handler:
 
        if (fcc->object) {
                fcc->called_scope = fcc->object->ce;
+               if (fcc->function_handler
+                && fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC) {
+                       fcc->object = NULL;
+               }
        }
        return retval;
 }