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

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容