fix: handle missing semicolon in abstract function declaration#3970
Closed
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
Closed
fix: handle missing semicolon in abstract function declaration#3970dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
Conversation
Fixes an "Undefined array key -1" error when processing abstract or interface method declarations without a semicolon. The findNext() call returns false when no semicolon is found, which needs to be checked before using the result in array access. Fixes squizlabs#3917
Contributor
Author
|
heads up - the CI is failing but it's not related to this PR. the failure is because the build phar workflow is using actions/upload-artifact@v3 which was deprecated and removed by GitHub on 2024-11-30. the code changes in this PR are working fine, it's just the CI infrastructure that needs updating to v4. |
Contributor
|
Third time - you are in the wrong repo.... |
Contributor
Author
|
my apologies - closing this. i'll submit to the correct repo. |
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 #3917
the issue occurs when processing abstract or interface method declarations that are missing a semicolon. the
findNext()call on line 129 returnsfalsewhen no semicolon is found after the closing bracket, which then gets used as an array index on line 130 ($tokens[($end - 1)]), resulting in an array key of -1.added a check to bail early if no semicolon is found, which prevents the undefined array key error while still allowing phpcs to report other issues with the code.
tested with the code sample from the issue - both phpcs and phpcbf now handle it without crashing.