Last active
October 8, 2016 16:05
-
-
Save mannion007/3ddb880d3d2acd938332358bc87f0707 to your computer and use it in GitHub Desktop.
Surprising behaviour of try/catch/finally block with return statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exceptionThrower() | |
{ | |
try { | |
throw new \Exception('Bang!'); | |
} catch(\Exception $e) { | |
echo 'An exception happened but I caught it!' . PHP_EOL; | |
return 5; | |
} finally { | |
echo 'I am just doing some cleanup...' . PHP_EOL; | |
return 10; | |
} | |
} | |
echo 'The result is ' . exceptionThrower(); | |
/** | |
* An exception happened but I caught it! | |
* I am just doing some cleanup... | |
* The result is 10 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment