News for hackers. Stuff that matters.
Re:PHP finally gets finally by randomdrake on Monday August 13, 2012 @10:14AM (#4375958)
This is an exciting step forward for being able to prevent repetitious code and handle exceptions more elegantly. More excitement will be had when we actually see this implemented in an upcoming version.

In case you are wondering why this link goes to the bottom of the page, the important bit is:

2012/08/13 Xinchen Hui: Close voting, RFC win the voting

The RFC is a bit dry and does explain some use cases, however, GoogleGuy (who is a really nice and helpful guy in the ##php channel) provided a wonderful explanation[1] that goes into more detail.

Accepting the RFC is just the first step, let's hope we can see this in the next version.

[1] - http://sheriframadan.com/2012/08/finally-keyword-in-php/

Re:PHP finally gets finally by TazeTSchnitzel on Monday August 13, 2012 @10:28AM (#4376018)
Oh, it will be, laruence is merging into master. Although whether it is 5.5 or 6.0 remains to be seen.

Also, looks like generators may come to vote soon since NikiC has asked on mailing list about it. http://wiki.php.net/rfc/generators

Re:PHP finally gets finally by kijin on Monday August 13, 2012 @10:42AM (#4376097)
This should have been implemented back in PHP 5.0, when exceptions were first introduced. A try-catch block without finally is only half complete!

But it's great to see half-complete features becoming fully complete, even if a few years late.

Re:PHP finally gets finally by TazeTSchnitzel on Monday August 13, 2012 @10:46AM (#4376122)
The main argument against it (that keeps coming up on ML) is destructors and resources cleaning up after themselves. Pretty weak argument though.
Re:PHP finally gets finally by ceol on Monday August 13, 2012 @01:24PM (#4376948)
Yes, considering OOP and exceptions are not dependent on each other.
Re:PHP finally gets finally by meritt on Monday August 13, 2012 @12:13PM (#4376569)
You should talk to Bjarne about leaving it out of C++ :)
Re:PHP finally gets finally by ori_b on Monday August 13, 2012 @01:02PM (#4376840)
C++ has a finally equivalent in a different form: Every object gets to clean up at the end of the scope as part of it's destructor. If you're not using RAII to manage cleaning up resources at the end of a scope, it's probably a good idea to change your style a bit.
Re:PHP finally gets finally by smsm42 on Monday August 13, 2012 @02:03PM (#4377143)
PHP perfectly can do the same. But I guess people want both.
Re:PHP finally gets finally by augusto_hp on Monday August 13, 2012 @12:07PM (#4376534)
It is definitely great. Although missed this for quite some years now, it is quite pleasing to see how the language continue to evolve throughout the years :)
Re:PHP finally gets finally by Joeri on Monday August 13, 2012 @02:13PM (#4377202)
I always loved the first response to the request to implement finally. It was so delightfully arrogant.

https://bugs.php.net/bug.php?id=32100

By the way, if you scroll down in that page there are two workaround solutions to get the finally behavior on any php5 version.

Re:PHP finally gets finally by spdy on Monday August 13, 2012 @03:28PM (#4377648)
Does it now catch system exceptions as well? Something that drove me away from php that i was not able to catch all errors inside an exception block.
Re:PHP finally gets finally by wwweston on Monday August 13, 2012 @06:23PM (#4378493)
I think this has been possible more or less since PHP introduced exceptions by using `set_error_handler`:

http://php.net/manual/en/function.set-error-handler.php

along with a function that throws exceptions, e.g.:

function exception_on_error($errnum,$errmsg) { throw new ErrorException($errmsg,$errnum); }

You can't catch all errors (sensibly including compile errors and unhandled exception errors), but it can get you pretty far.

Not that there aren't other reasons not to use PHP, but this one is manageable.

Re:PHP finally gets finally by irunbackwards on Monday August 13, 2012 @12:40PM (#4376712)
Is it possible to see the reasoning behind the 'no' votes?
Re:PHP finally gets finally by sharken on Monday August 13, 2012 @03:23PM (#4377617)
Short of asking the involved parties, the best you can do is to follow some of the PHP discussions on this topic, such as this one http://www.mail-archive.com/[email protected]/msg59731...

The first use-case for finally involved locking database tables, and then unlocking them in the finally clause. It would be pretty bad, if you could not guarantee the unlock would happen. So one would hope that has been properly taken care of :-)

Re:PHP finally gets finally by ExpiredLink on Monday August 13, 2012 @12:14PM (#4376575)
PHP has no destructors?
Re:PHP finally gets finally by pixelbath on Monday August 13, 2012 @12:37PM (#4376703)
How did you get that information from this post? PHP has had destructors in some form since 4.x, and true class destructors in 5.x: http://php.net/manual/en/language.oop5.decon.php
Re:PHP finally gets finally by meritt on Monday August 13, 2012 @12:43PM (#4376727)
My guess is he's from the C++ camp who tend to always suggest RAII as a replacement for 'finally' and RAII relies upon destructors.
Re:PHP finally gets finally by chc on Monday August 13, 2012 @01:22PM (#4376941)
Destructors aren't a good way to free resources in a garbage collected language.
Re:PHP finally gets finally by tomjen3 on Monday August 13, 2012 @04:33PM (#4377995)
I have yet to see a language that actually cleans up after itself. Many will attempt to free memory, but what about files, db connections, windows, sockets?
Re:PHP finally gets finally by reginaldo on Monday August 13, 2012 @05:31PM (#4378267)
Have you heard about Racket's custodians? [1] http://docs.racket-lang.org/reference/eval-model.html#(part....
Re:PHP finally gets finally by true_religion on Monday August 13, 2012 @04:04PM (#4377832)
Does ref-counting count as garbage collection?
Re:PHP finally gets finally by PaulHoule on Monday August 13, 2012 @01:03PM (#4376850)
sugoi!
Re:PHP finally gets finally by pjbeardsley on Monday August 13, 2012 @12:28PM (#4376658)
Finally.