From 4228871d67b1a146d7e1139dd6d0c99e90946cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 19 Apr 2024 10:24:55 +0200 Subject: [PATCH] reflection: Fix ReflectionFunction::getShortName() for Closures see php/php-src#13550 --- Zend/tests/closure_067.phpt | 20 ++++++++++++++++++++ ext/reflection/php_reflection.c | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/closure_067.phpt diff --git a/Zend/tests/closure_067.phpt b/Zend/tests/closure_067.phpt new file mode 100644 index 0000000000000..2738959509d7a --- /dev/null +++ b/Zend/tests/closure_067.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionFunction::getShortName() returns the full name for closures defined in namespaces. +--FILE-- +baz(); +$r = new \ReflectionFunction($c); +var_dump($r->getShortName()); +?> +--EXPECT-- +string(26) "{closure:Foo\Bar::baz():6}" diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 314a0359d3fc7..d2be2f869ae20 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3609,10 +3609,13 @@ ZEND_METHOD(ReflectionFunctionAbstract, getShortName) GET_REFLECTION_OBJECT_PTR(fptr); zend_string *name = fptr->common.function_name; - const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name)); - if (backslash) { - RETURN_STRINGL(backslash + 1, ZSTR_LEN(name) - (backslash - ZSTR_VAL(name) + 1)); + if (!(fptr->common.fn_flags & ZEND_ACC_CLOSURE)) { + const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name)); + if (backslash) { + RETURN_STRINGL(backslash + 1, ZSTR_LEN(name) - (backslash - ZSTR_VAL(name) + 1)); + } } + RETURN_STR_COPY(name); } /* }}} */