【问题标题】:Why php still report errors?为什么php还是报错?
【发布时间】:2020-06-18 07:01:15
【问题描述】:

simplesamlPHP 库中有代码

Logger::maskErrors(E_ALL);
$hidden = in_array(
    self::$HIDE_FROM_DISCOVERY, 
    $metadata['EntityAttributes'][self::$ENTITY_CATEGORY], 
    true
);
Logger::popErrorMask();

因此,他们决定将错误报告设置为 0,而不是使用 isset($metadata['EntityAttributes'][self::$ENTITY_CATEGORY]),然后将其恢复。问题是,当我将它作为脚本运行时,它可以工作,但是当我将它插入框架时,它仍然失败并出现错误。 虽然我在那里倾倒了水平,它真的被设置为0。

我还听说,如果您设置了用户定义的错误处理函数,那么 error_reporting() 设置将被完全忽略。但是全局搜索在项目中没有返回 set_error_handler。

【问题讨论】:

    标签: php error-handling error-reporting simplesamlphp


    【解决方案1】:

    仍然是set_error_handler(),我没有正确查看供应商文件夹。它在 Laravel 中工作的原因:

     public function handleError($level, $message, $file = '', $line = 0, $context = [])
        {
            if (error_reporting() & $level) {
                throw new ErrorException($message, 0, $level, $file, $line);
            }
        }
    

    但我的框架有这个:

        public function handleError($code, $message, $filename = '', $line = 0)
        {
            throw new \ErrorException($message, $code, 0, $filename, $line);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      相关资源
      最近更新 更多