Skip to content

Commit 90ee1c3

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix bug #66719
2 parents 8fbeebe + dfd05da commit 90ee1c3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #72595 (php_output_handler_append illegal write access). (cmb)
7+
. Fixed bug #66719 (Weird behaviour when using get_called_class() with
8+
call_user_func()). (Nikita)
79

810
- BCMath:
911
. Fixed bug #78238 (BCMath returns "-0"). (cmb)

Zend/tests/bug66719.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #66719: Weird behaviour when using get_called_class() with call_user_func()
3+
--FILE--
4+
<?php
5+
6+
class A
7+
{
8+
public static function who()
9+
{
10+
var_dump(get_called_class());
11+
}
12+
}
13+
class B extends A
14+
{
15+
public static function who()
16+
{
17+
parent::who();
18+
}
19+
}
20+
21+
class C
22+
{
23+
public static function test() {
24+
B::who();
25+
call_user_func(array(A::class, 'who'));
26+
call_user_func(array(B::class, 'parent::who'));
27+
}
28+
}
29+
30+
B::who();
31+
call_user_func(array(A::class, 'who'));
32+
call_user_func(array(B::class, 'parent::who'));
33+
34+
C::test();
35+
36+
?>
37+
--EXPECT--
38+
string(1) "B"
39+
string(1) "A"
40+
string(1) "A"
41+
string(1) "B"
42+
string(1) "A"
43+
string(1) "A"

Zend/zend_API.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
29992999
if (error) *error = estrdup("cannot access \"self\" when no class scope is active");
30003000
} else {
30013001
fcc->called_scope = zend_get_called_scope(frame);
3002+
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope)) {
3003+
fcc->called_scope = scope;
3004+
}
30023005
fcc->calling_scope = scope;
30033006
if (!fcc->object) {
30043007
fcc->object = zend_get_this_object(frame);
@@ -3012,6 +3015,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
30123015
if (error) *error = estrdup("cannot access \"parent\" when current class scope has no parent");
30133016
} else {
30143017
fcc->called_scope = zend_get_called_scope(frame);
3018+
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope->parent)) {
3019+
fcc->called_scope = scope->parent;
3020+
}
30153021
fcc->calling_scope = scope->parent;
30163022
if (!fcc->object) {
30173023
fcc->object = zend_get_this_object(frame);

0 commit comments

Comments
 (0)