美文网首页
[PHP错误异常]⑤--set_error_handler()

[PHP错误异常]⑤--set_error_handler()

作者: 子木同 | 来源:发表于2017-09-13 17:52 被阅读10次
Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png Paste_Image.png
<?php
header("content-type:text/html;charset=utf-8");
error_reporting(-1);
function customError($errno, $errmsg, $file, $line)
{
    echo "<b>错误代码:<b/>[{$errno}]{$errmsg}<br/>" . PHP_EOL;
    echo "<b>错误行号:</b>{$file}文件中的第{$line}行<br/>" . PHP_EOL;
    echo "<b>PHP版本:</b>" . PHP_VERSION . "(" . PHP_OS . ")<br/>" . PHP_EOL;
}
set_error_handler('customError');
echo $test;
?>
Paste_Image.png
<?php
header("content-type:text/html;charset=utf-8");
error_reporting(-1);
function customError($errno, $errmsg, $file, $line)
{
    echo "<b>错误代码:<b/>[{$errno}]{$errmsg}<br/>" . PHP_EOL;
    echo "<b>错误行号:</b>{$file}文件中的第{$line}行<br/>" . PHP_EOL;
    echo "<b>PHP版本:</b>" . PHP_VERSION . "(" . PHP_OS . ")<br/>" . PHP_EOL;
}

set_error_handler('customError');
echo $test;
echo "<hr/>";
settype($var, 'king');
echo "<hr/>";
//test();Fatal Error 无法使用自定义函数(向下执行)
trigger_error('this is a test of error', E_USER_ERROR);
echo "<hr/>";
//取消接管
restore_error_handler();
echo $king;
echo "<hr/>";
set_error_handler('customError', E_ALL & ~E_NOTICE);
echo $imooc;
echo "<hr/>";
settype($var,'king');
echo "<hr/>";
echo "continue";
?>
Paste_Image.png

相关文章

网友评论

      本文标题:[PHP错误异常]⑤--set_error_handler()

      本文链接:https://www.haomeiwen.com/subject/wwllsxtx.html