Repository navigation
Tokenizer/PHP: fix error when a const name is the last non-empty token in a file - #1461
Merged
jrfnl merged 2 commits intoAug 2, 2026
Merged
Conversation
…ration Co-authored-by: Sai Asish Y <say.apm35@gmail.com>
6 of 12 tasks
jrfnl
approved these changes
Aug 2, 2026
jrfnl
left a comment
Member
There was a problem hiding this comment.
@lazerg Thank you for another good PR. Sorry for the delayed response.
I identified PR #1462 as as largely a duplicate of this PR. As this one was opened earlier, I will accept this PR.
Having said that, there are small differences between the two PRs, with both PRs having their own merits. With that in mind, I will mash up the two PRs to be a "best of both worlds" and give both authors credit for their contribution.
The main reason for doing the mash-up:
- The
$i < $numTokenscondition is more descriptive as to why the condition is needed in comparison toisset($tokens[$i]) === true. - I always like to be explicit in documenting that a test case file contains a deliberate parse error / is intended to test a live coding situation.
Thank you again for your contribution. I will merge the updated PR once the build has passed.
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.
Description
Tokenizing a file where the name of a
constdeclaration is the last non-empty token, such asconst Awith nothing after it, aborts withAn error occurred during processing; checking has been aborted. The error message was: Undefined array key ... in src/Tokenizers/PHP.php.The loop that walks forward from the constant name to the next non-empty token ends with
$iequal to$numTokenswhen there is no such token, and the$tokens[$i] === '='check that follows then reads an index that does not exist. This adds anisset()guard so the check only runs when that token is present.Suggested changelog entry
Fixed a tokenizer error ("Undefined array key") which could occur when the name of a
constdeclaration was the last non-empty token in a file.Related issues/external references
Fixes #1451
Types of changes
PR checklist