Skip to content

Commit 6e11afc

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Ignore leading namespace separator in ReflectionParameter::__construct()
2 parents 757898b + 47f060c commit 6e11afc

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.9
44

5+
- Reflection:
6+
. Fixed bug GH-22324 (Ignore leading namespace separator in
7+
ReflectionParameter::__construct()). (jorgsowa)
58

69
02 Jul 2026, PHP 8.5.8
710

ext/reflection/php_reflection.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,9 +2515,20 @@ ZEND_METHOD(ReflectionParameter, __construct)
25152515
switch (Z_TYPE_P(reference)) {
25162516
case IS_STRING:
25172517
{
2518-
zend_string *lcname = zend_string_tolower(Z_STR_P(reference));
2519-
fptr = zend_hash_find_ptr(EG(function_table), lcname);
2520-
zend_string_release(lcname);
2518+
zend_string *fname = Z_STR_P(reference);
2519+
zend_string *lcname;
2520+
if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) {
2521+
/* Ignore leading "\" */
2522+
ALLOCA_FLAG(use_heap)
2523+
ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap);
2524+
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1);
2525+
fptr = zend_fetch_function(lcname);
2526+
ZSTR_ALLOCA_FREE(lcname, use_heap);
2527+
} else {
2528+
lcname = zend_string_tolower(fname);
2529+
fptr = zend_fetch_function(lcname);
2530+
zend_string_release(lcname);
2531+
}
25212532
if (!fptr) {
25222533
zend_throw_exception_ex(reflection_exception_ptr, 0,
25232534
"Function %s() does not exist", Z_STRVAL_P(reference));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
ReflectionParameter::__construct(): a leading "\" in the function name is ignored
3+
--FILE--
4+
<?php
5+
6+
function demo(string $arg) {}
7+
8+
$p = new ReflectionParameter("\\demo", 0);
9+
var_dump($p->getName());
10+
11+
$p = new ReflectionParameter("demo", 0);
12+
var_dump($p->getName());
13+
14+
?>
15+
--EXPECT--
16+
string(3) "arg"
17+
string(3) "arg"

0 commit comments

Comments
 (0)