Johannes, On Tue, Jul 24, 2012 at 9:48 AM, Johannes Schlüter <johan...@schlueters.de>wrote:
> On Tue, 2012-07-24 at 19:20 +0800, Laruence wrote: > > Hi: > > As the previous threads disscussed, I make a implemention. > > > > here is the RFC: https://wiki.php.net/rfc/finally > > > > any suggestions? > > > > thanks > > As PHP has destructors there is less need for "finally" compared to > other languages. What are the cases where an extra language construct is > needed? (i.e. one can also use C++-like RAII things ...) > I'm not sure I agree with that statement. Finally is a routine level cleanup tool, while destructors are object level cleanup tools. So while it is possible to make every routine into an object, at some point it just becomes ridiculous. That means that every method that allocates resources would need to be a first-class object, which could get quite messy very fast. If you went by "possible", half the proposals for the language wouldn't be accepted (password hashing, generators, goto, Class name to scalar resolution, T_AS for closures, type hints, call-time dereferencing, traits, classes, etc). All of that behavior is possible without the language sugar that they bring. The main drive for adding them is that it makes a developers life a lot easier. Rather than dealing with yet another level of abstraction to add an object, adding a simple finally clause would make implementing that sort of cleanup FAR easier. Additionally, the destructor isn't called until the object goes out of scope. That could be after the method call (a scope block higher). So the only way to fully emulate the finally block would be to construct the object inside of the method in question. So it's not as simple as "just put it in a destructor and you'll be fine"... My $0.02 at least...