Skip to content

Commit 097043d

Browse files
committed
Fix called scope assignment in autoloader
We should use the scope specified in the spl_autoload_register() call, not whatever LSB scope just so happens to be active at the time of the autoloader call.
1 parent e0e4a61 commit 097043d

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

ext/spl/php_spl.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
403403
zval params[1];
404404
zval retval;
405405
zend_string *func_name;
406-
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
407406

408407
fci.size = sizeof(fci);
409408
fci.retval = &retval;
@@ -431,13 +430,7 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
431430
if (Z_ISUNDEF(alfi->obj)) {
432431
fci.object = NULL;
433432
fcic.object = NULL;
434-
if (alfi->ce &&
435-
(!called_scope ||
436-
!instanceof_function(called_scope, alfi->ce))) {
437-
fcic.called_scope = alfi->ce;
438-
} else {
439-
fcic.called_scope = called_scope;
440-
}
433+
fcic.called_scope = alfi->ce;
441434
} else {
442435
fci.object = Z_OBJ(alfi->obj);
443436
fcic.object = Z_OBJ(alfi->obj);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
SPL autoloader should not do anything magic with called scope
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public static function register() {
8+
spl_autoload_register([Test::class, 'autoload']);
9+
}
10+
11+
public static function autoload($class) {
12+
echo "self=" . self::class, ", static=", static::class, "\n";
13+
}
14+
}
15+
16+
class Test2 extends Test {
17+
public static function register() {
18+
spl_autoload_register([Test2::class, 'autoload']);
19+
}
20+
21+
public static function runTest() {
22+
class_exists('FooBar');
23+
}
24+
}
25+
26+
Test::register();
27+
Test2::register();
28+
Test2::runTest();
29+
30+
?>
31+
--EXPECT--
32+
self=Test, static=Test
33+
self=Test, static=Test2

0 commit comments

Comments
 (0)