A PHP internals pre-RFC discussion proposes deprecating `return` inside `finally` blocks. Currently, a `return` in a `finally` block silently discards any pending exception or return value from the `try`/`catch` block, with no error or notice. This is inconsistent with PHP's handling of `break`, `continue`, and `goto` inside `finally`, which are already compile errors. The original RFC author admitted adding it only because Java allowed it, even though he thought it made no sense — and Java itself warns about it. The author implemented the deprecation and scanned the top ~5000 Composer packages, finding only 12 occurrences across 9 packages, with 3 appearing to be genuine latent bugs. The proposal is to deprecate in PHP 8.6 and eventually make it an error in a future major version. Responses from PHP internals contributors (Gina P. Banyard, Larry Garfield) are supportive, with Larry suggesting it could be folded into the omnibus deprecations RFC rather than needing its own RFC.

12m read timeFrom externals.io
Post cover image
121 Impressions