【发布时间】:2008-08-31 03:57:29
【问题描述】:
我正在飞跃:我的 PHP 脚本将全部失败!
至少,这是我所希望的……`
我不想(实际上)包装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);
这工作正常,返回:
抱歉,第 17 行出现错误。导致 错误提示未定义变量: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();
这会返回:
致命错误:调用未定义函数:imafakefunction() in /Library/WebServer/Documents/experimental/errorhandle.php 第 17 行
为什么我的自定义错误处理程序没有捕获未定义的函数?这会导致其他问题吗?
【问题讨论】:
标签: php