我正在飞跃:我的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
为什么我的自定义错误处理程序捕获未定义的功能?这会造成其他问题吗?