Zend: suggest similar names for undefined function/class/method error - #22589
Draft
jorgsowa wants to merge 6 commits into
Draft
Zend: suggest similar names for undefined function/class/method error#22589jorgsowa wants to merge 6 commits into
jorgsowa wants to merge 6 commits into
Conversation
TimWolla
requested changes
Jul 4, 2026
TimWolla
left a comment
Member
There was a problem hiding this comment.
Some feedback regarding the implementation.
The JIT compiler had its own hand-written stub for raising "Call to undefined function" errors that bypassed the new Levenshtein suggestion logic, since it duplicated the error message instead of reusing the interpreter's helper. Extract the shared logic into zend_undefined_function_error() and call it from both the VM helper and the JIT stub.
jorgsowa
force-pushed
the
feat/levenshtein-suggestions
branch
from
August 3, 2026 21:50
ad14e87 to
3c111b3
Compare
… constant expressions zend_ast_evaluate_inner() (first-class callables used as default parameter values, const initializers, etc.) still threw the plain "Call to undefined function %s()" message, unlike the VM/JIT and dynamic-call paths. Reuse zend_find_similar_function() there too.
"(did you mean strlen()?)" reads oddly since the () is already part of the call syntax right before it. Use "(did you mean strlen?)" instead, matching the class suggestion format which never had parens.
NickSdot
reviewed
Aug 5, 2026
| try { | ||
| test(); | ||
| } catch (Error $e) { | ||
| echo $e->getMessage(), "\n"; |
Contributor
There was a problem hiding this comment.
Suggested change
| echo $e->getMessage(), "\n"; | |
| echo $e::class, ': ', $e->getMessage(), "\n"; |
NickSdot
reviewed
Aug 5, 2026
NickSdot
reviewed
Aug 5, 2026
NickSdot
reviewed
Aug 5, 2026
NickSdot
reviewed
Aug 5, 2026
NickSdot
reviewed
Aug 5, 2026
NickSdot
reviewed
Aug 5, 2026
Contributor
|
I like this. Added some nit comments. Context is the ongoing effort in #22799. |
jorgsowa
marked this pull request as draft
August 5, 2026 21:43
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.
An idea that I came up with during the implementation of case-sensitive PHP. Small DX improvement over the typos and mistakes in function/classes names.
Because this covers the case of an undefined function, it shouldn't decrease the performance of a properly working application.
Adaptive threshold: names under 8 characters must be within edit distance 1 to be suggested; names 8+ characters allow distance 2. This avoids noisy suggestions for short identifiers (a 1-character edit on a 4-letter name is a big relative change) while still catching multi-typo mistakes in longer names.
We can extend it to constants, etc., if the idea is good enough.