Skip to content

Fix undefined array key crash in FunctionDocblockManipulator#11816

Open
eyupcanakman wants to merge 1 commit intovimeo:masterfrom
eyupcanakman:fix/docblock-manipulator-end-11793
Open

Fix undefined array key crash in FunctionDocblockManipulator#11816
eyupcanakman wants to merge 1 commit intovimeo:masterfrom
eyupcanakman:fix/docblock-manipulator-end-11793

Conversation

@eyupcanakman
Copy link
Copy Markdown
Contributor

@eyupcanakman eyupcanakman commented Apr 19, 2026

Fixes #11793

For abstract and interface methods, the function-body slice in FunctionDocblockManipulator::__construct excludes the trailing ;. The return-type scanner can reach the last index of $chars while still inside the word-char branch, and accessing $chars[$i + 1] triggers an Undefined array key warning that Psalm's error handler turns into a RuntimeException.

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 FunctionDocblockManipulator from reading past the end of the return-type token stream by guarding $chars[$i + 1] with isset(), fixing a crash when processing methods whose signatures end with ; (e.g., interface/abstract methods).

Adds regression coverage in ReturnTypeManipulationTest for interface methods (including namespaced return types) where fixing MismatchingDocblockReturnType should remove the redundant @return docblock without errors.

Reviewed by Cursor Bugbot for commit bc877d8. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

1 participant