====== Request for Comments: Supports finally keyword ====== * Version: 1.0 * Date: 2012/07/24 * Author: Xinchen Hui * Status: Implemented * First Published at: http://wiki.php.net/rfc/finally * Alternative Reading: http://sheriframadan.com/2012/08/finally-keyword-in-php/ by GoogleGuy ===== Introduction ===== This RFC is try to introduce 'finally' support for exceptions. which is requested from FR #32100, #36779 without this feature, user have to write codes like following one to do cleanup while an un-handlable exception occurred: introducing finally is not about save one or two lines for such situation, it's about give the user a more proper way to handle such issue. ===== Proposal ===== The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated. the most confuse part is call "return in try/catch block", in this case the finally block will still be called the above script will output: this will be called //return int(2) and for nesting try catch finally: will output: 123432int(1) There are also lots of edge cases could be found in the Test&Examples section blow ===== Patch ===== * Patch: https://github.com/laruence/php-src/tree/finally ===== Tests & Examples ===== * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_001.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_002.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_003.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_004.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_005.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/catch_finally_006.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/try_finally_001.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/try_finally_002.phpt * https://github.com/laruence/php-src/blob/finally/Zend/tests/try_finally_003.phpt ===== Vote ===== * Yes * No ===== Changelog ===== * 2012/07/24 Xinchen Hui: Initial version * 2012/07/26 Xinchen Hui: Update RFC * 2012/08/06 Xinchen Hui: Open voting * 2012/08/13 Xinchen Hui: Close voting, RFC win the voting * 2012/08/15 Xinchen Hui: Committed