A userland solution is possible making use of destructors to run anonymous
functions (see How can I get around the lack of a finally block in
PHP?<http://stackoverflow.com/a/9244733/90527>).
However, there are a number of issues with this approach (some are outlined
in the link), and language-level support would be preferable.

As for implementation, would it be possible to hook into whatever PHP has
in the way of frame disposal? That approach would have one of the same
issues as the userland solution ("finally" blocks won't run until the
current scope is exited), but is at least a partial solution. Would it be
possible to implement partial block scope? The idea being to add some sort
of guard when entering a block with an attached "finally", so that when the
block is exited, the finally runs. Please excuse my ignorance if none of
this is viable; I'll do my homework now.

Reply via email to