Skip to content

Comments

fix: handle missing semicolon in abstract function declaration#3970

Closed
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
dmzoneill-forks:fix/issue-3917-undefined-array-key
Closed

fix: handle missing semicolon in abstract function declaration#3970
dmzoneill wants to merge 1 commit intosquizlabs:masterfrom
dmzoneill-forks:fix/issue-3917-undefined-array-key

Conversation

@dmzoneill
Copy link
Contributor

Fixes #3917

the issue occurs when processing abstract or interface method declarations that are missing a semicolon. the findNext() call on line 129 returns false when 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.

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
@dmzoneill
Copy link
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.

@jrfnl
Copy link
Contributor

jrfnl commented Feb 11, 2026

Third time - you are in the wrong repo....

@jrfnl jrfnl closed this Feb 11, 2026
@dmzoneill
Copy link
Contributor Author

my apologies - closing this. i'll submit to the correct repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undefined index in FunctionDeclarationSniff

2 participants