1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

reflection: Fix ReflectionFunction::getShortName() for Closures (#14001)

see php/php-src#13550
This commit is contained in:
Tim Düsterhus
2024-04-19 12:14:16 +02:00
committed by GitHub
parent 2447cb25c6
commit d03d436528
2 changed files with 26 additions and 3 deletions

View File

@@ -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}"

View File

@@ -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);
}
/* }}} */