Skip to content

Deprecate returning from a finally block - #22509

Open
aldemeery wants to merge 1 commit into
php:masterfrom
aldemeery:deprecate-return-in-finally
Open

Deprecate returning from a finally block#22509
aldemeery wants to merge 1 commit into
php:masterfrom
aldemeery:deprecate-return-in-finally

Conversation

@aldemeery

@aldemeery aldemeery commented Jun 29, 2026

Copy link
Copy Markdown

This PR implements the "return inside finally" deprecation from the PHP 8.6 deprecations RFC.

https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_returning_from_a_finally_block

Returning from a finally block now raises E_DEPRECATED at compile time.
The check tracks the return lexically. Returning from the try or catch part is still fine, and a return inside a nested closure stays fine because the closure has its own scope. A return in a nested try that is itself inside the finally does get flagged though.

Zend/tests/try/finally_return_deprecation.phpt covers all of that.
The rest of the diff adds the deprecation line to existing tests that already return from a finally.

@Girgias

Girgias commented Aug 10, 2026

Copy link
Copy Markdown
Member

Could this be rebased with the conflict fixed and marked as ready? (ideally before tomorrow's tagging)

Comment thread Zend/tests/gc/gc_050.phpt Outdated
OK
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
OK No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the EOL before EOF in the tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, missed that you already requested this. 🙂

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

before return
before return in inner finally
outer finally run
outer finally run No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add trailing newlines to all files.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for all files

@aldemeery
aldemeery force-pushed the deprecate-return-in-finally branch from 8199001 to 44c42a6 Compare August 12, 2026 00:13
@aldemeery

aldemeery commented Aug 12, 2026

Copy link
Copy Markdown
Author

@Girgias Rebased and marked ready.

Also fixed the trailing newlines you and @iluuu1994 flagged...Thanks for the nudge.

@aldemeery
aldemeery marked this pull request as ready for review August 12, 2026 00:22
@aldemeery
aldemeery requested review from Girgias and iluuu1994 August 12, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants