Edit report at http://bugs.php.net/bug.php?id=32100&edit=1
ID: 32100
Comment by: bat at flurf dot net
Reported by: ceefour at gauldong dot net
Summary: Request 'finally' support for exceptions
Status: Closed
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: *
PHP Version: 5.*
Block user comment: N
Private report: N
New Comment:
Here's an idea! Find all the people who think "finally" isn't needed in
PHP. Invite them to go back to programming Visual Basic, because
they're ignorant. The rest can work on implementing it. Easy!
Previous Comments:
------------------------------------------------------------------------
[2011-05-05 11:52:26] ealexs at gmail dot com
PHP++ for finally in PHP ;)
my code:
disableSIPTrunk (10 lines of code)
try
{
// do some stuff
}
finally
{
enableSIPTrunk (10 lines of code)
}
// saves duplicate code and it's very elegant !
------------------------------------------------------------------------
[2011-04-05 21:16:06] adam dot pippin at ohmedia dot ca
---
Disable user permission checking
try
{
Call a half a dozen methods
}
finally
{
Re-enable user permission checking
}
---
The ten year old discussion I found on the issue
(http://marc.info/?l=php-internals&m=96774165717219&w=3) doesn't seem
terribly applicable to my case. Specifically, it suggests:
---
try {
... modify contents ...
} catch {
... any error recovery code here ...
}
... cleanup code ...
---
Except my code doesn't 'recover' from errors. It runs back up the call
stack and reports the error to the user. I have absolutely zero use for
a catch here. My workaround (which, unlike a basic rethrow preserves the
line/file):
---
Disable permission checking
try
{
Run methods
}
catch (Exception $e)
{
Enable permission checking
throw new Exception($e->getMessage(), $e->getCode(), $e);
}
Enable permission checking
---
The workaround simply requires a few extra lines of code and a bunch of
duplicated code. But hey, finally isn't required, so it's all good.
------------------------------------------------------------------------
[2011-03-20 10:44:01] php at techdp dot co dot uk
+++ for finally in PHP. It is one of the most elegant and expressive
keywords in modern programming, allowing precise capture of error
handling semantics, and easy authorship of bug-free code!
------------------------------------------------------------------------
[2011-02-19 17:34:09] gunter at web dot com
++ for finally in PHP.
------------------------------------------------------------------------
[2011-02-17 22:02:08] attila dot m dot magyar at gmail dot com
I agree with the previous comments, a 'finally' keyword would be nice
and useful when it fits to the conventions and standards applied in a
project. If it's not hairy to implement and wouldn't introduce
instability in the core, I'd reassure PHP developers to add this feature
in a future release.
Best regards,
Athos
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=32100
--
Edit this bug report at http://bugs.php.net/bug.php?id=32100&edit=1