From cfd5105cf6bd6fc44438ea6043239b4b6428866a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 30 Apr 2024 16:25:36 +0200 Subject: [PATCH] reflection: Fix ReflectionFunction::getShortName() for first class callables Fix fixes an incorrect fix in php/php-src#14001. --- Zend/tests/closure_068.phpt | 13 +++++++++++++ ext/reflection/php_reflection.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/closure_068.phpt diff --git a/Zend/tests/closure_068.phpt b/Zend/tests/closure_068.phpt new file mode 100644 index 0000000000000..977d3946770ab --- /dev/null +++ b/Zend/tests/closure_068.phpt @@ -0,0 +1,13 @@ +--TEST-- +ReflectionFunction::getShortName() returns the short name for first class callables defined in namespaces. +--FILE-- +getShortName()); +?> +--EXPECT-- +string(3) "foo" diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d2be2f869ae20..8d5895d1f6c1e 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3609,7 +3609,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getShortName) GET_REFLECTION_OBJECT_PTR(fptr); zend_string *name = fptr->common.function_name; - if (!(fptr->common.fn_flags & ZEND_ACC_CLOSURE)) { + if ((fptr->common.fn_flags & (ZEND_ACC_CLOSURE | ZEND_ACC_FAKE_CLOSURE)) != 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));