PHP 7.2.0 Beta 3 Released

Voting

Please answer this simple SPAM challenge: six minus one?
(Example: nine)

The Note You're Voting On

ohcc at 163 dot com
1 year ago
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
?>

<< Back to user notes page

To Top