2012-08-11 40 views
0

我使用從NETTUTS以下腳本:這是爲什麼PHP腳本錯誤不是我發送電子郵件的致命錯誤?

// Our custom error handler 
function error_engine($number, $message, $file, $line, $vars) 

{ 
    $email = " 
     <p>An error ($number) occurred on line 
     <strong>$line</strong> and in the <strong>file: $file.</strong> 
     <p> $message </p>"; 

    $email .= "<pre>" . print_r($vars, 1) . "</pre>"; 

    $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    // Email the error to someone... 
    error_log($email, 1, '[email protected]', $headers); 


    if (($number !== E_NOTICE) && ($number < 2048)) { 
     die("There was an error. Please try again later."); 
    } 
} 

// We should use our custom function to handle errors. 
set_error_handler('error_engine'); 

它工作正常的通知和警告等,但,當我故意打破我的腳本,通過改變「mysqli_connect」說「mysqy_connct」我得到的致命錯誤打印在屏幕上,並沒有電子郵件!

就像是超越這種類型的錯誤日誌/報告的範圍錯誤?

我在做什麼錯?

回答

3

它列在documentation

以下錯誤類型不能與用戶定義的函數來處理:E_ERROR,E_PARSE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,最E_STRICT的其中的set_error_han dler()被調用的文件中提出。

+0

啊好的,謝謝。 – absentx 2012-08-11 18:25:26

+0

@absentx請接受一個答案。 – mAu 2012-08-12 08:10:39

3

set_error_handler/set_exception_handler不處理所有可能的錯誤。也就是說,解析錯誤不會被它捕獲。我無法確切地告訴你它沒有處理什麼。一般的規則是,這些處理程序被調用的東西,會被抓的,當try catch或當trigger_error被稱爲

爲了不受set_error_handler/set_exception_handler許多框架陷入陷阱的錯誤使用和register_shutdown_function組合error_get_last

相關問題