我正在飛躍:我的PHP腳本將全部失敗優雅!set_error_handler不工作我想如何工作
至少,這就是我希望的......
我不想換行(幾乎)在嘗試... catch語句每一行,所以我想我最好的選擇是爲我的文件的開始創建自定義錯誤處理程序。
我測試出來練習頁:
function customError($level,$message,$file,$line,$context) {
echo "Sorry, an error has occured on line $line.<br />";
echo "The function that caused the error says $message.<br />";
die();
}
set_error_handler("customError");
echo($imAFakeVariable);
這工作正常,返回:
Sorry, an error has occured on line 17. The function that caused the error says Undefined variable: imAFakeVariable.
然而,這種設置並不未定義功能工作。
function customError($level,$message,$file,$line,$context) {
echo "Sorry, an error has occured on line $line.<br />";
echo "The function that caused the error says $message.<br />";
die();
}
set_error_handler("customError");
imAFakeFunction();
這將返回:
Fatal error: Call to undefined function: imafakefunction() in /Library/WebServer/Documents/experimental/errorhandle.php on line 17
爲什麼我的自定義錯誤處理程序捕獲未定義的功能?這會造成其他問題嗎?