【问题标题】:why in php I am getting _default error message along with custom error message i set with set_error_handler为什么在 php 中我收到 _default 错误消息以及我使用 set_error_handler 设置的自定义错误消息
【发布时间】:2019-01-09 11:17:36
【问题描述】:

为什么还要使用我用 set_error_handler 设置的自定义错误处理程序消息获取默认错误处理程序消息,这是我下面的代码

     function custom_handler($error_level,$error_message){
 echo   "[$error_level] $error_message";
}

set_error_handler("custom_handler",E_WARNING);
require_once('try.php')

这是输出

"[2] require_once(try.php): 无法打开流: 没有这样的文件或 目录致命错误:require_once():需要打开失败 'try.php' (include_path='D:\software\xampp\php\PEAR') 在 D:\software\xampp\htdocs\samples\code.php 第 14 行"

【问题讨论】:

标签: php


【解决方案1】:

根据php手册:

require 与 include 相同,但在失败时它也会 产生致命的 E_COMPILE_ERROR 级别错误。换句话说,它将 停止脚本,而 include 仅发出警告 (E_WARNING) 允许脚本继续。

以下错误类型无法用用户定义的方式处理 功能:E_ERROR、E_PARSE、E_CORE_ERROR、E_CORE_WARNING、 E_COMPILE_ERROR、E_COMPILE_WARNING 和大部分 E_STRICT 在 调用 set_error_handler() 的文件。

您的自定义处理程序显示 E_WARNING,默认处理程序显示 E_COMPILE_ERROR。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 2022-01-21
    • 2014-04-12
    • 1970-01-01
    • 2020-01-17
    相关资源
    最近更新 更多