Req #36779 [Opn->Dup]: Request 'finally' support for exceptions
| From: | aharvey@php.net | Date: | Tue, 14 Aug 2012 01:17:12 +0000 |
| Subject: | Req #36779 [Opn->Dup]: Request 'finally' support for exceptions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172588@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=36779&edit=1
ID: 36779
Updated by: aharvey@php.net
Reported by: since71 at gmail dot com
Summary: Request 'finally' support for exceptions
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: Scripting Engine problem
Operating System: All
PHP Version: 5.1.2
Block user comment: N
Private report: N
New Comment:
Implemented on master (see request #32100 and https://wiki.php.net/rfc/finally for more details).
Previous Comments:
------------------------------------------------------------------------
[2012-02-28 17:31:49] kiall at managedit dot ie
I think these three snippets illustrate why finally would be very useful..
Python: http://codepad.org/zcVRYPzS
Ruby: http://codepad.org/uORFxLVy
PHP: http://codepad.org/t0WtzZ9p
------------------------------------------------------------------------
[2011-08-09 20:17:36] cmanley at xs4all dot nl
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.
------------------------------------------------------------------------
[2006-03-18 03:47:34] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=36779&edit=1