我正在迈出一步:我的PHP脚本将全部失败!
至少,这是我所希望的`
我不想(实际上)包装<code>中的每一行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 occurred 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
为什么我的自定义错误处理程序不能捕获未定义的函数?这会导致其他问题吗?