php error_get_last(),PHP捕获异常register_shutdown_function和error_get_last的使用
生活随笔
收集整理的這篇文章主要介紹了
php error_get_last(),PHP捕获异常register_shutdown_function和error_get_last的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
register_shutdown_function
注冊一個會在php中止時執行的函數,注冊一個?callback?,它會在腳本執行完成或者?exit()?后被調用。
error_get_last
獲取最后發生的錯誤,包含type(錯誤類型),message(錯誤消息),file(發生錯誤所在的文件),line(發生錯誤所在的行)的一個數組,如果沒有錯誤則返回null。
兩個函數可以結合使用,獲取程序發生的錯誤,并記錄日志信息。
以下是個簡單例子:class?errors
{
/**
*??回調函數
*/
function?shutdown()
{
//?獲取錯誤
$error?=?error_get_last();
if?($error)?{
//?記錄日志信息
var_dump($error);
}
}
}
class?test{
function?test_shutdown()
{
//?注冊一個會在php中止時執行的函數?shutdown
register_shutdown_function([new?errors(),?'shutdown']);
//?這里調用一個不存在的函數測試
testaa();
}
}
$test?=?new?test();
$test->test_shutdown();
總結
以上是生活随笔為你收集整理的php error_get_last(),PHP捕获异常register_shutdown_function和error_get_last的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 长安睿行S50汽车C1212车速信号是什
- 下一篇: 阜阳驾车到昌吉回族自治州车师古道走哪条高