Fixed bug #77877 (call_user_func() passes $this to satatic methods).

This commit is contained in:
Dmitry Stogov 2019-04-11 14:24:04 +03:00
parent cd8312a77e
commit a1b7ccdfc6
3 changed files with 29 additions and 0 deletions

2
NEWS
View File

@ -5,6 +5,8 @@ PHP NEWS
- Core: - Core:
. Fixed bug #77345 (Stack Overflow caused by circular reference in garbage . Fixed bug #77345 (Stack Overflow caused by circular reference in garbage
collection). (Alexandru Patranescu, Nikita, Dmitry) 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 . Implemented request #76148 (Add array_key_exists() to the list of
specially compiled functions). (Majkl578) specially compiled functions). (Majkl578)
. Fixed bug #76430 (__METHOD__ inconsistent outside of method). . Fixed bug #76430 (__METHOD__ inconsistent outside of method).

23
Zend/tests/bug77877.phpt Normal file
View File

@ -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

View File

@ -3170,6 +3170,10 @@ get_function_via_handler:
if (fcc->object) { if (fcc->object) {
fcc->called_scope = fcc->object->ce; fcc->called_scope = fcc->object->ce;
if (fcc->function_handler
&& fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC) {
fcc->object = NULL;
}
} }
return retval; return retval;
} }