Zend: Return anonymous closure names in zend_get_callable_name_ex() (#19011)

This returns the usual `{closure:FILE_NAME/FUNCTION:LINE_NO}` for anonymous functions rather than `Closure::__invoke` this is visible for `is_callable()` and any Engine call that uses `zend_fcall_info_init()` to get the name of the callable.

Related to GH-18063.
This commit is contained in:
Gina Peter Banyard 2025-07-03 12:01:11 +01:00 committed by GitHub
parent 4492a4219a
commit f91f80ca19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 12 deletions

View file

@ -42,9 +42,9 @@ Foo::__invoke
bool(true)
Foo::__invoke
bool(true)
Closure::__invoke
bool(true)
Closure::__invoke
{closure:foo():9}
bool(true)
{closure:foo():9}
bool(true)
Closure::__invoke
bool(true)

View file

@ -4160,13 +4160,10 @@ try_again:
if (ce == zend_ce_closure) {
const zend_function *fn = zend_get_closure_method_def(Z_OBJ_P(callable));
if (fn->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) {
if (fn->common.scope) {
return zend_create_member_string(fn->common.scope->name, fn->common.function_name);
} else {
return zend_string_copy(fn->common.function_name);
}
if ((fn->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) && fn->common.scope) {
return zend_create_member_string(fn->common.scope->name, fn->common.function_name);
}
return zend_string_copy(fn->common.function_name);
}
return zend_string_concat2(

View file

@ -57,11 +57,11 @@ Array
[5] => E::f
[6] => E::g
[7] => E::__invoke
[8] => Closure::__invoke
[8] => {closure:%s:%d}
)
Array
(
[name] => Closure::__invoke
[name] => {closure:%s:%d}
[type] => 1
[flags] => 20593
[level] => 8
@ -161,7 +161,7 @@ Array
[8] => Array
(
[name] => Closure::__invoke
[name] => {closure:%s:%d}
[type] => 1
[flags] => 20593
[level] => 8