您可以指定自己的自定義PHP錯誤處理程序。下面是一個簡單的例子:
function log_error_handler($errno, $str, $file, $line)
{
switch($errno) {
case E_USER_ERROR:
add_log("PHP Error", "Error $errno on line $line in $file: $str", "fatal");
exit(1);
break;
case E_USER_WARNING:
add_log("PHP Warning", "Warning $errno on line $line in $file: $str", "warning");
break;
case E_USER_NOTICE:
add_log("PHP Notice", "Notice $errno on line $line in $file: $str", "note");
break;
default:
//uncomment this next line to catch
// add_log("PHP", "Unknown error $errno on line $line in $file: $str", "note");
break;
}
}
function add_log($code, $message, $type = 'message', $program = null){
//do something like email the admin or enter in the data in to the bug tracking software db
}
// ### function to log php errors ####
set_error_handler("log_error_handler");