一起源码网

标题: php:析构函数调用的示例代码 [打印本页]

作者: 云文章    时间: 2020-3-17 21:30
标题: php:析构函数调用的示例代码
php调用

class a{
    function construct(){
        echo "start to construct a obj
";
    }   
    function pide($a,$b)
    {   
        //exit(1);//destruct called
        return $a/$b; //destruct called when $b=0;
    }   
    function add($a,$b)
    {   
        throw new Exception ("daone");//destruct called
        return $a+$b;
    }   
    function destruct(){
        echo "start to destruct
";
    }   
}
try{
    $first = new a();
    //$r = $first->pide(4,0);
    $first->add(4,0);
}
catch(Exception $e) 
{
    echo "cath exception 
";
}

从上面的例子可以看出,php(不管外面有没有try catch),直接的情况下,都会调用。


作者: V74402    时间: 2022-7-2 07:57
怎么从源代码下载音乐




欢迎光临 一起源码网 (https://www.171739.xyz/) Powered by Discuz! X3.3