Repository navigation
Fix GH-8623: Better error message for first-class callable of undefined function - #25647
Open
GuilhermeAltmann wants to merge 1 commit into
Open
GuilhermeAltmann wants to merge 1 commit into
GuilhermeAltmann wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-8623.
First-class callables compile to an
INIT_*opcode immediately followed byZEND_CALLABLE_CONVERT. When the function does not exist, theINIT_*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_CONVERTand emits a closure-specific message instead: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_NAMEviazend_undefined_function_helper(missing(...),'missing'(...),Foo\missing(...))ZEND_INIT_DYNAMIC_CALLfor string callables ($name(...)), by passing the first-class callable context tozend_init_dynamic_call_string()zend_ast.c), where the AST is already known to be a first-class callableOut of scope, per the discussion in GH-8623 and #7019:
get_methodobject handler, which does not know about the call kind.foo(?)):ZEND_CALLABLE_CONVERT_PARTIALis 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 underZend/tests/first_class_callable/, one underext/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).