Repository navigation
Report deprecated return in finally block on PHP 8.6 - #7079
Merged
Merged
Conversation
PHP 8.6 deprecates returning from a finally block at compile time. Like PHP, the rule looks for return statements lexically in the finally block, including nested try and catch blocks, but not in closures, arrow functions, anonymous classes or nested function declarations. A nested try's own finally block is reported by its own TryCatch node. Amp-Thread-ID: https://ampcode.com/threads/T-01a1dfa1-37b0-77d8-96bc-e3bdf810d9d7
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.
PHP 8.6 deprecates returning from a finally block (RFC, implemented in php/php-src@e721b3f).
The new level 0 rule
ReturnInFinallyRulereportsReturning from a finally block is deprecated in PHP 8.6.(identifierfinally.deprecatedReturn).Like PHP, which emits the deprecation at compile time, it looks for
returnstatements lexically in the finally block, including nestedtryandcatchblocks, but not in closures, arrow functions, anonymous classes or nested function declarations. A nestedtry's ownfinallyblock is reported when the rule runs on thatTryCatchnode, so nothing is reported twice. The test data mirrors the cases in php-src'sfinally_return_deprecation.phpt.Version gating follows
BacktickRule:PhpVersions::deprecatesReturnInFinally()together withcheckWholePhpVersionRange.