<?phpclass test { public $start; public $end; public function __construct() { echo "__construct<br />"; $this->start = microtime(true); } public function test() { echo "in test()<br />"; throw new exception("error", 500); // 抛出异常 } public function __destruct() { echo "__destruct<br />"; }}$test = new test();$test->test();立即学习“PHP免费学习笔记(深入)”;
方法里抛出异常后,不会调用析构函数:
try异常后能调用析构函数:
闪灵CMS企业建站系统是淄博闪灵网络科技有限公司开发的一款专门为企业建站提供解决方案的产品,前端模板样式主打HTML5模板,以动画效果好、页面流畅、响应式布局为特色,程序主体采用PHP+MYSQL构架,拥有独立自主开发的一整套函数、标签系统,具有极强的可扩展性,设计师可以非常简单的开发出漂亮实用的模板。系统自2015年发布第一个版本以来,至今已积累上万用户群,为上万企业提供最优质的建站方案。
0
<?phpclass Test { public $start; public $end; public function __construct() { echo "__construct<br />"; $this->start = microtime(true); } public function test() { echo "in test()<br />"; try { // try 异常 throw new Exception("error", 500); // 抛出异常 } catch(Exception $e) { } } public function __destruct() { echo "__destruct<br />"; }}$test = new Test();$test->test();立即学习“PHP免费学习笔记(深入)”;
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号