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) bool(true)
Foo::__invoke Foo::__invoke
bool(true) bool(true)
Closure::__invoke {closure:foo():9}
bool(true) bool(true)
Closure::__invoke {closure:foo():9}
bool(true) bool(true)
Closure::__invoke Closure::__invoke
bool(true) bool(true)

View file

@ -4160,14 +4160,11 @@ try_again:
if (ce == zend_ce_closure) { if (ce == zend_ce_closure) {
const zend_function *fn = zend_get_closure_method_def(Z_OBJ_P(callable)); 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.fn_flags & ZEND_ACC_FAKE_CLOSURE) && fn->common.scope) {
if (fn->common.scope) {
return zend_create_member_string(fn->common.scope->name, fn->common.function_name); return zend_create_member_string(fn->common.scope->name, fn->common.function_name);
} else { }
return zend_string_copy(fn->common.function_name); return zend_string_copy(fn->common.function_name);
} }
}
}
return zend_string_concat2( return zend_string_concat2(
ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(ce->name), ZSTR_LEN(ce->name),

View file

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