note 124120 rejected from function.exit by cmb
| From: | cmb@php.net | Date: | Fri, 16 Aug 2019 13:26:31 +0000 |
| Subject: | note 124120 rejected from function.exit by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211894@lists.php.net to get a copy of this message | ||
Note Submitter: photon0 at gmail dot com
----
Might be evident for some but I think the documentation is missing how exit behaves when placed in a
try-catch. It only exits the current try and continue after the catch! Consider the following code:
foreach (['trois','petits','chats'] as $x){
try{
echo $x.' [before]';
exit;
echo ' [after]';
}catch(Exception $ex){}
echo ' [out]\n';
}
//in PHP 7.2 I have the following output
trois [before] [out]
petits [before] [out]
chats [before] [out]