Skip to content

Commit 921e105

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix bug #66719
2 parents a892647 + 90ee1c3 commit 921e105

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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
@@ -3326,6 +3326,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33263326
if (error) *error = estrdup("cannot access \"self\" when no class scope is active");
33273327
} else {
33283328
fcc->called_scope = zend_get_called_scope(frame);
3329+
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope)) {
3330+
fcc->called_scope = scope;
3331+
}
33293332
fcc->calling_scope = scope;
33303333
if (!fcc->object) {
33313334
fcc->object = zend_get_this_object(frame);
@@ -3339,6 +3342,9 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
33393342
if (error) *error = estrdup("cannot access \"parent\" when current class scope has no parent");
33403343
} else {
33413344
fcc->called_scope = zend_get_called_scope(frame);
3345+
if (!fcc->called_scope || !instanceof_function(fcc->called_scope, scope->parent)) {
3346+
fcc->called_scope = scope->parent;
3347+
}
33423348
fcc->calling_scope = scope->parent;
33433349
if (!fcc->object) {
33443350
fcc->object = zend_get_this_object(frame);

0 commit comments

Comments
 (0)