Commit 47f060ca330 for php.net

commit 47f060ca330e16f9ea9b7b2b3edf5c4861219128
Author: Jorg Sowa <jorg.sowa@gmail.com>
Date:   Tue Jun 16 00:15:53 2026 +0200

    Ignore leading namespace separator in ReflectionParameter::__construct()

    Strip a leading '\\' before lowercasing, matching ReflectionFunction::__construct().

    Fixes GH-22324
    Closes GH-22325

diff --git a/NEWS b/NEWS
index 2ea7143e39e..1a069963bd5 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 8.4.24

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

 02 Jul 2026, PHP 8.4.23

diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 1f5b448f85f..eba5600c16a 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2480,9 +2480,20 @@ ZEND_METHOD(ReflectionParameter, __construct)
 	switch (Z_TYPE_P(reference)) {
 		case IS_STRING:
 			{
-				zend_string *lcname = zend_string_tolower(Z_STR_P(reference));
-				fptr = zend_hash_find_ptr(EG(function_table), lcname);
-				zend_string_release(lcname);
+				zend_string *fname = Z_STR_P(reference);
+				zend_string *lcname;
+				if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) {
+					/* Ignore leading "\" */
+					ALLOCA_FLAG(use_heap)
+					ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap);
+					zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1);
+					fptr = zend_fetch_function(lcname);
+					ZSTR_ALLOCA_FREE(lcname, use_heap);
+				} else {
+					lcname = zend_string_tolower(fname);
+					fptr = zend_fetch_function(lcname);
+					zend_string_release(lcname);
+				}
 				if (!fptr) {
 					zend_throw_exception_ex(reflection_exception_ptr, 0,
 						"Function %s() does not exist", Z_STRVAL_P(reference));
diff --git a/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt b/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt
new file mode 100644
index 00000000000..b0a7827c276
--- /dev/null
+++ b/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt
@@ -0,0 +1,17 @@
+--TEST--
+ReflectionParameter::__construct(): a leading "\" in the function name is ignored
+--FILE--
+<?php
+
+function demo(string $arg) {}
+
+$p = new ReflectionParameter("\\demo", 0);
+var_dump($p->getName());
+
+$p = new ReflectionParameter("demo", 0);
+var_dump($p->getName());
+
+?>
+--EXPECT--
+string(3) "arg"
+string(3) "arg"