Greetings internals,

While working on rewriting the PHP docs about errors and error handling [1]
I came across a change of behaviour in an edge case of an edge case.

finally blocks are meant to be always executed regardless that an Exception
has been thrown or not, which it does, however a call to exit() (or die()
as they are aliases).
This can be seen with the following example: https://3v4l.org/6Tger

However, there is one case where finally blocks are executed when exit() is
used, namely when a generator has a finally block and exit() is called
during its traversal, an example of this in action can be seen here:
https://3v4l.org/HGKHS

The behaviour of this edge case of an edge case is highly dependent on the
version of PHP where this is run, PHP 5.5, 5.6, 7.0, early version of PHP
7.1, PHP 7.2.0, PHP 7.2.1, and PHP 8.0 all run the finally block on exit().
Later versions of PHP 7.1, 7.2.2 and above and PHP 7.3 and 7.4 all skip the
finally block.

Frankly this is already going to be a mess to document, but this begs the
question is there a "bug" in executing the finally blocks in generators
during a call to exit() or is the "bug" to not execute finally blocks when
exit() is called.

I've CCed the PHP 8.0 RMs as if the consensus is that skipping finally
blocks after a call to exit() is performed it would be wise to change this
behaviour in PHP 8.0 only and land this ASAP, even though it's a BC break.

Interested in hearing your thoughts.

Best regards,

George P. Banyard

[1] https://github.com/php/doc-en/pull/320

Reply via email to