throw new 和new的区别

<?php
class a extends Exception{
function __construct(){
parent::__construct('a',1);

}

}
throw new a(12,1);
这俩有啥区别,用了好久了,刚才好奇就想出来一个这么个问题

阅读 9.5k
1 个回答
try {
    $obj = new Exception('12', 1);
    throw $obj;
} catch (Exception $e) {
    print_r($e);
}
//=======================这是等价的
try {
    throw new Exception('12', 1);
} catch (Exception $e) {
    print_r($e);
}

就是抛出一个对象。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题