Re:PHP doesn't need 'finally'
by wvenable on Friday December 10, 2010 @11:24AM
(#1992111)
Just like with C++ (which also doesn't have finally) you can use RAII techniques with PHP. Object destructors will get called when your object goes out of scope. I use this to clean up resources (mainly rollback transations) in the case of exceptions.
In fact, now with PHP 5.3 and closures one could emulate finally quite easily: just create an object that runs the closure on destruction and it will be called at the end of the block.
Finally would still, however, be a welcome addition to the language.
In fact, now with PHP 5.3 and closures one could emulate finally quite easily: just create an object that runs the closure on destruction and it will be called at the end of the block.
Finally would still, however, be a welcome addition to the language.