Skip to content

Zend: suggest similar names for undefined function/method/class errors#22589

Open
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:feat/levenshtein-suggestions
Open

Zend: suggest similar names for undefined function/method/class errors#22589
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:feat/levenshtein-suggestions

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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.

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback regarding the implementation.

Comment thread Zend/zend_execute.c Outdated
Comment thread Zend/zend_execute_API.c Outdated
Comment thread Zend/zend_execute.c Outdated
Comment thread Zend/zend_execute.c Outdated
Comment thread Zend/zend_execute.c Outdated
Comment thread Zend/zend_string.c Outdated
jorgsowa added 2 commits July 4, 2026 17:12
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants