Skip to content

Don't return from a finally block (deprecated in PHP 8.6) - #400

Merged
trowski merged 1 commit into
amphp:3.xfrom
danog:php86-finally
Nov 20, 2026
Merged

trowski merged 1 commit into
amphp:3.xfrom
danog:php86-finally

Conversation

@danog

@danog danog commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

PHP 8.6 deprecates returning from a finally block, and it reports this when the file is compiled:

Deprecated: Returning from a finally block is deprecated in src/Driver/Http2Driver.php on line 1344

It's the only occurrence in src (I linted every file on PHP 8.6.0). Applications whose error handler turns deprecations into exceptions fail as soon as Http2Driver is loaded.

The return in handleStreamEnd() only skipped releasing a stream that had already been closed, so that check is now part of the release condition. Behaviour stays the same with one exception: a return in finally also discards an exception thrown in the try block, so if the body queue or the trailers deferred threw while the stream was being closed, that exception was silently dropped. It now propagates, which I believe was the intent.

CI also runs on PHP 8.6, with and without FFI. psalm is skipped on those jobs because psalm.phar requires PHP <= 8.5; the 8.5 jobs still run it. On 8.6 locally, the test suite passes (138 tests), and so do php-cs-fixer (with the PHP_CS_FIXER_IGNORE_ENV the workflow already sets) and composer-require-checker.

PHP 8.6 emits "Returning from a finally block is deprecated" when compiling Http2Driver.php. The
return in handleStreamEnd() only skipped releasing a stream that was already closed: the check is now
part of the release condition. As a side effect, an exception thrown in the try block is no longer
discarded when the stream closed meanwhile.

CI also runs on PHP 8.6 (without psalm, whose phar requires PHP <= 8.5).
@trowski
trowski merged commit cb929c3 into amphp:3.x Nov 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants