trycatchfinally

name = 'silk';
    try {
        return $arr;
    } finally {
        $arr->name = "xiaoyang";
    }
}

function test2()
{
    $arr = [
        'name' => 'silk',
        'age' => 18
    ];
    try {
        return $arr;
    } finally {
        $arr['name'] = "xiaoyang";
    }
}

function test3()
{
    $i = 0;
    try {
        return ++$i;
    } finally {
        $i = $i + 2;
    }
}

function test4()
{
    $i = 0;
    try {
//        return ++$i;
        throw new Exception("new Exception");
    } catch (Exception $e) {
        return --$i;
    } finally {
        return --$i;
    }
}

var_dump(test());
var_dump(test1());
var_dump(test2());
var_dump(test3());
var_dump(test4());

 

你可能感兴趣的:(php,Java)