note 119726 added to language.exceptions
| From: | ohcc at 163 dot com | Date: | Thu, 11 Aug 2016 09:25:52 +0000 |
| Subject: | note 119726 added to language.exceptions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206261@lists.php.net to get a copy of this message | ||
If a TRY has a FINALLY, a RETURN either in the TRY or a CATCH won't terminate the script. Code
in the same block after the RETURN will not be executed, and the RETURN itself will be
"copied" to the bottom of the FINALLY block to be executed.
a RETURN in the FINALLY block will override value(s) returned from the TRY or a CATCH block.
An EXIT or a DIE always terminate the script after themselves.
code 1
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
$bar++;
}
}
echo foo(); // 2
?>
code 2
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
$bar++;
return $bar;
}
}
echo foo(); //2
?>
code 3
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
return 100;
}
}
echo foo(); //100
?>
----
Server IP: 72.52.91.14
Probable Submitter: 118.117.77.147
----
Manual Page -- http://php.net/manual/en/language.exceptions.php
Edit -- https://master.php.net/note/edit/119726
Del: integrated -- https://master.php.net/note/delete/119726/integrated
Del: useless -- https://master.php.net/note/delete/119726/useless
Del: bad code -- https://master.php.net/note/delete/119726/bad+code
Del: spam -- https://master.php.net/note/delete/119726/spam
Del: non-english -- https://master.php.net/note/delete/119726/non-english
Del: in docs -- https://master.php.net/note/delete/119726/in+docs
Del: other reasons-- https://master.php.net/note/delete/119726
Reject -- https://master.php.net/note/reject/119726
Search -- https://master.php.net/manage/user-notes.php