当前位置:Gxlcms > PHP教程 > thrownew和new的区别

thrownew和new的区别

时间:2021-07-01 10:21:17 帮助过:26人阅读

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

}

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

回复内容:

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

}

}
throw new a(12,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);
}

就是抛出一个对象。

人气教程排行