Fix undefined array key crash in FunctionDocblockManipulator#11816
Open
eyupcanakman wants to merge 1 commit intovimeo:masterfrom
Open
Fix undefined array key crash in FunctionDocblockManipulator#11816eyupcanakman wants to merge 1 commit intovimeo:masterfrom
eyupcanakman wants to merge 1 commit intovimeo:masterfrom
Conversation
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 #11793
For abstract and interface methods, the function-body slice in
FunctionDocblockManipulator::__constructexcludes the trailing;. The return-type scanner can reach the last index of$charswhile still inside the word-char branch, and accessing$chars[$i + 1]triggers anUndefined array keywarning that Psalm's error handler turns into aRuntimeException.Guard the access with
isset(). The sibling/and*branches aren't reachable at end of scan.Note
Low Risk
Low risk bugfix that adds a bounds check to prevent a runtime exception when manipulating return types on abstract/interface methods; behavior should be unchanged except for avoiding the crash.
Overview
Prevents
FunctionDocblockManipulatorfrom reading past the end of the return-type token stream by guarding$chars[$i + 1]withisset(), fixing a crash when processing methods whose signatures end with;(e.g., interface/abstract methods).Adds regression coverage in
ReturnTypeManipulationTestfor interface methods (including namespaced return types) where fixingMismatchingDocblockReturnTypeshould remove the redundant@returndocblock without errors.Reviewed by Cursor Bugbot for commit bc877d8. Bugbot is set up for automated code reviews on this repo. Configure here.