summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/tests/bug77877.phpt23
-rw-r--r--Zend/zend_API.c4
2 files changed, 27 insertions, 0 deletions
diff --git a/Zend/tests/bug77877.phpt b/Zend/tests/bug77877.phpt
new file mode 100644
index 0000000000..9e0181e1a6
--- /dev/null
+++ b/Zend/tests/bug77877.phpt
@@ -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
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 00161da07e..b3a617ee62 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3027,6 +3027,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;
}