【问题标题】:Error reporting is blocked on parse errors解析错误时阻止错误报告
【发布时间】:2016-05-28 04:07:44
【问题描述】:

我将首先写下我确实看到了类似的问题,并且我确实尝试了建议的解决方案。

我正在运行一个 cli,当我故意在 php 文件中放置一个解析错误时,我在 stdOut 中没有收到错误。
我正在使用以下配置:
error_reporting 的 22527 是
ini_set('error_reporting', E_ALL|E_STRICT);

PHP 5.5.20 (cli) (built: Jan  9 2015 11:20:56) 
php -i | grep error 
display_errors => STDOUT => STDOUT
display_startup_errors => Off => Off
error_append_string => no value => no value
error_log => no value => no value
error_prepend_string => no value => no value
error_reporting => 22527 => 22527
html_errors => Off => Off
ignore_repeated_errors => Off => Off
log_errors => Off => Off
log_errors_max_len => 1024 => 1024
track_errors => Off => Off
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off

添加:如果我添加自己的致命处理程序:

    function fatal_handler() {
        $error = error_get_last();
        if ($error !== null) {
            echo ("\n\nERROR occured!\nFile [{$error['file']}].\nLine: [{$error['line']}].\nMessage: [{$error['message']}]\n\n");
        }
        exit(1);
    }
register_shutdown_function("fatal_handler");

我确实看到了 stdio 中的错误。

以下是对我来说不会产生错误的代码示例(带有解析错误)

class A{
   const AAA = 'aaa';
   static public function Result(A::AAA){

   }
}

【问题讨论】:

  • 可以添加解析错误的示例吗?我在 STDERR 中得到“PHP Parse error:”,即使使用display_errors => Off => Off; PHP 5.5.14 (cli)。
  • 为什么不使用 apache 日志或错误日志来查看 php 错误?为什么是cli?
  • 因为我正在开发 CLI。
  • @AlexBlex 查看更新
  • 你怎么称呼这段代码? php myfile.php 还是有shebang?

标签: php linux error-handling error-reporting php-5.5


【解决方案1】:

error_reporting => 22527 => 22527 等价于E_ALL & ~E_DEPRECATED & ~E_STRICT

使用-1E_ALL 错误级别(PHP 5.4 中的E_ALL | E_STRICT)显示所有错误。

在ini文件中设置php.ini

error_reporting = -1

以下内容不起作用,因为代码包含解析错误,因此永远不会调用 ini_set()

<?php

ini_set('error_reporting', -1)

class A 
{
    const AAA = 'aaa';

    static public function Result(A::AAA) 
    {
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 2012-12-14
    • 2016-12-15
    • 2016-09-28
    • 2011-10-26
    • 2015-09-03
    • 2013-01-21
    相关资源
    最近更新 更多