Skip to content

Report deprecated return in finally block on PHP 8.6 - #7079

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
return-in-finally-deprecation
Nov 15, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
return-in-finally-deprecation

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

PHP 8.6 deprecates returning from a finally block (RFC, implemented in php/php-src@e721b3f).

The new level 0 rule ReturnInFinallyRule reports Returning from a finally block is deprecated in PHP 8.6. (identifier finally.deprecatedReturn).

Like PHP, which emits the deprecation at compile time, it 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 when the rule runs on that TryCatch node, so nothing is reported twice. The test data mirrors the cases in php-src's finally_return_deprecation.phpt.

Version gating follows BacktickRule: PhpVersions::deprecatesReturnInFinally() together with checkWholePhpVersionRange.

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
@ondrejmirtes
ondrejmirtes merged commit cd16cbc into 2.3.x Nov 15, 2026
443 of 448 checks passed
@ondrejmirtes
ondrejmirtes deleted the return-in-finally-deprecation branch November 15, 2026 14:44
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