我在调试PHP应用程序时遇到困难。
当我包含我的php文件时,不会引发任何异常。我尝试使用不会触发的set_error_handler,但error_get_last()返回null。
set_error_handler(function() {
echo 'Here is your error!';
var_dump(error_get_last());
echo 'Sike!';
});
try {
include('viewer.php');
} catch (Exception $e) {
echo 'I really ought to tell you something went wrong here. But I won\'t';
}
restore_error_handler();
exit();
输出:
Here is your error!NULL Sike!
有第三种方法可以找出实际出了什么问题吗?
答案 0 :(得分:0)
从php docs尝试
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting, so let it fall
// through to the standard PHP error handler
return false;
}
switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
set_error_handler("myErrorHandler");