|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-18 03:47 UTC] since71 at gmail dot com
Description: ------------ A previous thread for a request to add "finally" support for exceptions was relatively quickly killed in what seemed, to me, the beginning of a potentially useful thread (http://bugs.php.net/bug.php?id=32100) and I would like to re-open it. The original requestors comments rings true for many of us developing PHP. FWIW: I heartily agree that "finally" should be implemented in some (hopefully near) future version of PHP. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
I agree. Not having "finally" is a language shortcoming. One example I just ran into that made me cuss at PHP is this. Without finally, one cannot use breaks in a try construct as break ends execution of the current for, foreach, while, do-while or switch structure. Code example: do { $lock = new PseudoLock(); try { // do stuff if (...) { break; // this is a no-no without finally } } catch(Exception $e) { $lock = null; // release lock throw $e; } $lock = null; // release lock // Do more stuff. } while (!$satisfied); Note how the inner break will cause both resource lock release attempts to be skipped. If the finally construct existed, the break would first pass through the finally where the lock can be released, and then pass out of it's loop structure. That's how it works in other languages.