class a{
function construct(){
echo "start to construct a obj\n";
}
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\n";
}
}
try{
$first = new a();
//$r = $first->pide(4,0);
$first->add(4,0);
}
catch(Exception $e)
{
echo "cath exception \n";
}从上面的例子可以看出,php抛出异常(不管外面有没有try catch),直接退出的情况下,都会调用析构函数。
以上就是php:析构函数调用的示例代码的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号