私は飛躍しています:私のPHPスクリプトはすべて正常に失敗します! set_error_handlerは動作しませんどのように私はそれが働きたい
は、少なくとも、それは私が、私は(事実上)のtry ... 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
はなぜ私のカスタムエラーハンドラが未定義の関数をキャッチされていませんか?これが原因となる他の問題はありますか?