You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Awkward error using first-class callable syntax with missing function #8623
Fatal error: Uncaught Error: Call to undefined function missing()
But I expected this output instead:
Fatal error: Uncaught Error: Unable to create closure from undefined function missing()
When using the first-class callable syntax on a missing function, the error message claims the user is calling a function. However, this should only be creating a closure.
I thought the (...) syntax would only try to create a closure. Does it actually try to call the function with a ... argument if it's not found?
If you use the original Closure::fromCallable() method, the error is different.
Closure::fromCallable('missing');
Uncaught TypeError: Failed to create closure from callable: function "missing" not found or invalid function name
The problem is that the callable syntax causes an INIT_* opcode to be emitted, and afterwards an CALLABLE_CONVERT to convert to the call frame to closure. However, if the function is not defined, the INIT_* fails, causing the error message.
@nikic, like you already said there: "Though maybe that makes the message in the common case slightly harder to understand." Particularly, the word "reference" might cause some confusion regarding references (&). OTOH, the wording is actually more precise even for the call-case.
Particularly, the word "reference" might cause some confusion regarding references (&). OTOH, the wording is actually more precise even for the call-case.
If I may offer an opinion, even though it's throwing an error, prefixing with "Unable to", might help.
From:
Reference to private method Foo::bar() from Baz
To:
Unable to reference to private method Foo::bar() from Baz
If the code that's throwing the error is always just resolving functions, then you could say Locating instead of Reference. If locating the function fails then naturally any use of it would fail after.
Following the earlier discussion (particularly nikic's comment about not threading call-kind information through the get_method handler), here is a proposal limited to the function code paths:
First-class callables compile to an INIT_* opcode immediately followed by ZEND_CALLABLE_CONVERT. On the error paths for undefined functions we can check whether the next opcode is ZEND_CALLABLE_CONVERT and emit a closure-specific message instead of the misleading "Call to undefined function". This covers:
ZEND_INIT_DYNAMIC_CALL for string callables ('missing'(...), $name(...)), and
constant-expression FCC evaluation in zend_ast.c, where the AST is already known to be a first-class callable.
Suggested wording, aligned with Closure::fromCallable()'s existing TypeError ("Failed to create closure from callable: ..."):
Failed to create closure from undefined function missing()
Common calls are unaffected (missing() still reports "Call to undefined function missing()").
Out of scope: methods (per #7019, the error comes from the get_method object handler) and partial applications (foo(?) — ZEND_CALLABLE_CONVERT_PARTIAL is not adjacent to the INIT opcode, so runtime PFAs keep the current message).
I have a working patch with tests (full Zend suite green on NTS debug, plus ZTS and opcache sanity runs). If the approach and wording look good, I'll open a PR.
(The quoted paragraph above was drafted with the help of an LLM coding agent.)
Activity
cmb69 commentedon May 24, 2022
The problem is that the callable syntax causes an
INIT_*opcode to be emitted, and afterwards anCALLABLE_CONVERTto convert to the call frame to closure. However, if the function is not defined, theINIT_*fails, causing the error message.Having a proper error message has been discussed, but is not generally possible. Maybe we should just document this issue more clearly?
othercorey commentedon May 24, 2022
Documentation of the expected error would greatly improve this.
cmb69 commentedon May 24, 2022
I keep this ticket here for a while; maybe someone comes up with a way to improve the error message.
nikic commentedon May 24, 2022
Any thoughts on the suggestion to use more generic error messages (that don't use "call" terminology) from #7019 (comment)?
cmb69 commentedon May 25, 2022
@nikic, like you already said there: "Though maybe that makes the message in the common case slightly harder to understand." Particularly, the word "reference" might cause some confusion regarding references (
&). OTOH, the wording is actually more precise even for the call-case.othercorey commentedon May 25, 2022
If I may offer an opinion, even though it's throwing an error, prefixing with "Unable to", might help.
From:
To:
If the code that's throwing the error is always just resolving functions, then you could say
Locatinginstead ofReference. If locating the function fails then naturally any use of it would fail after.othercorey commentedon Jul 6, 2022
@nikic I don't suppose there's a chance of making this error more generic for 8.2?
GuilhermeAltmann commentedon Nov 22, 2026
I'd like to pick this up.
Following the earlier discussion (particularly nikic's comment about not threading call-kind information through the
get_methodhandler), here is a proposal limited to the function code paths:I have a working patch with tests (full Zend suite green on NTS debug, plus ZTS and opcache sanity runs). If the approach and wording look good, I'll open a PR.
(The quoted paragraph above was drafted with the help of an LLM coding agent.)
Improve error message for first-class callable of undefined method