Skip to content

Commit 66910ee

Browse files
authored
ext/spl: ignore leading namespace separator in spl_autoload() (#22323)
Strip a leading "\\" before lowercasing, mirroring zend_lookup_class_ex(), so both spellings resolve identically.
1 parent 7f4e0f4 commit 66910ee

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

ext/spl/php_spl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ PHP_FUNCTION(spl_autoload)
301301
pos_len = (int)ZSTR_LEN(file_exts);
302302
}
303303

304-
lc_name = zend_string_tolower(class_name);
304+
if (ZSTR_VAL(class_name)[0] == '\\') {
305+
lc_name = zend_string_alloc(ZSTR_LEN(class_name) - 1, 0);
306+
zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(class_name) + 1, ZSTR_LEN(class_name) - 1);
307+
} else {
308+
lc_name = zend_string_tolower(class_name);
309+
}
305310
while (pos && *pos && !EG(exception)) {
306311
pos1 = strchr(pos, ',');
307312
if (pos1) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
spl_autoload(): a leading "\" in the class name is ignored
3+
--FILE--
4+
<?php
5+
6+
set_include_path(__DIR__);
7+
spl_autoload_extensions(".inc");
8+
9+
spl_autoload("DualIterator");
10+
var_dump(class_exists("DualIterator", false));
11+
12+
spl_autoload("\\RecursiveDualIterator");
13+
var_dump(class_exists("RecursiveDualIterator", false));
14+
15+
?>
16+
--EXPECT--
17+
bool(true)
18+
bool(true)

0 commit comments

Comments
 (0)