php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36779 Request 'finally' support for exceptions
Submitted: 2006-03-18 03:47 UTC Modified: 2012-08-14 01:17 UTC
Votes:45
Avg. Score:4.7 ± 0.6
Reproduced:37 of 40 (92.5%)
Same Version:20 (54.1%)
Same OS:28 (75.7%)
From: since71 at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.1.2 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 10 = ?
Subscribe to this entry?

 
 [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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-09 20:17 UTC] 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.
 [2012-02-28 17:31 UTC] 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
 [2012-08-14 01:17 UTC] aharvey@php.net
-Status: Open +Status: Duplicate -Package: Feature/Change Request +Package: Scripting Engine problem
 [2012-08-14 01:17 UTC] aharvey@php.net
Implemented on master (see request #32100 and https://wiki.php.net/rfc/finally for more details).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC