[php-src] PR #25647: Fix GH-8623: Better error message for first-class callable of undefined function
| From: | GuilhermeAltmann | Date: | Sun, 22 Nov 2026 03:11:10 +0000 |
| Subject: | [php-src] PR #25647: Fix GH-8623: Better error message for first-class callable of undefined function | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40884@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25647
Author: GuilhermeAltmann
Fixes GH-8623.
First-class callables compile to an
INIT_* opcode immediately followed by
ZEND_CALLABLE_CONVERT. When the function does not exist, the INIT_* opcode
fails with "Call to undefined function", which is misleading because no call is taking
place — the call frame is about to be converted into a closure.
This PR checks, on the error paths for undefined functions, whether the next opcode is
ZEND_CALLABLE_CONVERT and emits a closure-specific message instead:
```
Failed to create closure from undefined function missing()
```
The wording is aligned with the existing Closure::fromCallable() TypeError
("Failed to create closure from callable: function "missing" not found or invalid
function name").
Covered code paths:
- ZEND_INIT_FCALL_BY_NAME / ZEND_INIT_NS_FCALL_BY_NAME via
zend_undefined_function_helper (missing(...),
'missing'(...), Foo\missing(...))
- ZEND_INIT_DYNAMIC_CALL for string callables ($name(...)), by passing the
first-class callable context to zend_init_dynamic_call_string()
- constant-expression FCC evaluation (zend_ast.c), where the AST is already known to be
a first-class callable
Out of scope, per the discussion in GH-8623 and #7019:
- Methods: the "Call to undefined method" error originates in the get_method
object handler, which does not know about the call kind.
- Partial applications (foo(?)): ZEND_CALLABLE_CONVERT_PARTIAL is not
adjacent to the INIT opcode (the argument sends sit in between), so runtime PFAs keep the current
message.
Common calls are unaffected: missing() still reports "Call to undefined function
missing()".
Tests: new Zend/tests/first_class_callable/gh8623.phpt, and updated expectations of
five existing tests that asserted the old message in FCC context (four under
Zend/tests/first_class_callable/, one under ext/opcache).
Validation: full test suite on an NTS debug build (17151 tests, no new failures), the Zend suite on
a ZTS debug build, and sanity runs with opcache enabled (the INIT → CALLABLE_CONVERT sequence is
preserved by the optimizer).
> Parts of this PR description were drafted with the help of an LLM coding agent.