[php-src] master: reflection: Fix ReflectionFunction::getShortName() for Closures (#14001)

From: Date: Fri, 19 Apr 2024 10:14:23 +0000
Subject: [php-src] master: reflection: Fix ReflectionFunction::getShortName() for Closures (#14001)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-128165@lists.php.net to get a copy of this message
Author: Tim Düsterhus (TimWolla) Committer: GitHub (web-flow) Pusher: TimWolla Date: 2024-04-19T12:14:16+02:00 Commit: https://github.com/php/php-src/commit/d03d4365281480a515ca1852fc7183dc10bc6e0a Raw diff: https://github.com/php/php-src/commit/d03d4365281480a515ca1852fc7183dc10bc6e0a.diff reflection: Fix ReflectionFunction::getShortName() for Closures (#14001) see php/php-src#13550 Changed paths: A Zend/tests/closure_067.phpt M ext/reflection/php_reflection.c Diff: 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-- +<?php +namespace Foo; + +class Bar { + public function baz() { + return function () { + + }; + } +} + +$c = (new Bar())->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); } /* }}} */

« previous php.cvs (#128165) next »