Home  >  Article  >  Backend Development  >  大神帮忙看上 如何没执行小弟我的异常处理代码

大神帮忙看上 如何没执行小弟我的异常处理代码

WBOY
WBOYOriginal
2016-06-13 13:06:37995browse

大神帮忙看下 怎么没执行我的错误处理代码啊

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php //定义Error_Handler 函数
/** * 定义Error_Handler 函数
 * * * @param $error_level 错误级别
 * * @param $error_message 错误信息
 * * @param $file 错误所在文件
 * * @param $line 错误所在行数
 * * */
//屏蔽程序中的错误
error_reporting (0);
set_error_handler("error_handler");
function error_handler ($error_level, $error_message, $file, $line) {
    echo "11111111111";
}
myerror_method();
?>



上面这段代码 调用了没定义的函数myerror_method(); 应该执行我的自定义错误处理函数error_handler()啊
奈何 echo "11111111111";这句没有执行啊,求大牛帮看下呢,跪谢!

------解决方案--------------------
你调用不存在函数,这是致命错误,直接导致脚本结束

你试试 echo $sakdfhgkjad;不存在的变量,则可正常调用自定义错误处理函数

BTW:
如果你非要在致命错误情况下,也能调用,则试试register_shutdown_function函数
------解决方案--------------------
php程序执行时有两个阶段
1、预编译阶段:完成对程序文件的语法分析,并生成中间代码
2、执行阶段:运行中间代码

set_error_handler("error_handler");
是在执行阶段执行的
所以不能处理预编译阶段的错误
------解决方案--------------------
探讨

php程序执行时有两个阶段
1、预编译阶段:完成对程序文件的语法分析,并生成中间代码
2、执行阶段:运行中间代码

set_error_handler("error_handler");
是在执行阶段执行的
所以不能处理预编译阶段的错误
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn