CodeIgniter 错误报告 1.7.x 和 2.x 之间的差异

CodeIgniter Error Reporting Difference between 1.7.x and 2.x

提问人:jaydisc 提问时间:9/26/2013 最后编辑:jaydisc 更新时间:9/30/2013 访问量:490

问:

我有两个相同的 Debian Squeeze 服务器运行 php 5.3.3-7+squeeze17,一个运行 1.7.x,另一个运行 2.1.4。

在 1.7 安装中,当我调用调用未定义模型方法的控制器方法时,页面输出:

Fatal error: Call to undefined method Example_Model::get_series_and_products() in /opt/git/online_live/application/controllers/members.php on line 2549

但是,在 2.1.4 上根本没有输出。 在未定义的函数输出文本之前插入语句,但之后的语句不插入。echo

这两个站点在其 VirtualHost 配置中都将 php error_reporting设置为 -1,这似乎覆盖了开发的config.php定义的 ENVIRONMENT 设置,该设置将 error_reporting 设置为 E_ALL。

以下是我用于输出的一些额外代码:

echo ini_get('error_reporting');
echo '<br>';
echo phpversion();

两者的输出相同:

-1  
5.3.3-7+squeeze17

因此,似乎没有其他任何事情胜过我的error_reporting。

在 2.1.4 的 application/config/config.php 中(未显示错误):

$config['log_threshold'] = 4; // All Messages

在 1.7 中(显示错误的地方):

$config['log_threshold'] = 0;

但我认为该设置是针对 CI 保留的文件系统日志,而不是内联错误。

phpInfo() 在两台主机上反映相同的error_log值:

error_log:              no value    no value
error_reporting:        -1          22527

是什么导致了这种差异?

php codeigniter codeigniter-2 错误报告

评论

0赞 Jakub 9/26/2013
两种 CI 设置的日志级别是多少?(application/config/config.php for 2.1.X) 另外,当您比较时,您是否看到相同的错误日志记录?最后很难说,因为我们没有太多信息可以继续。phpinfo()
0赞 jaydisc 9/26/2013
我想如果 ini_get('error_reporting') 报告 -1,那么config.php中的内容并不重要,但我还是在上面添加了 log_threshold 参数。这是你所指的参数吗?phpInfo() 对两者产生相同的值: error_append_string:无值 error_log:无值 error_prepend_string:无值 error_reporting:-1

答:

2赞 xiankai 9/26/2013 #1

编辑:如果您的设置是使用 或 设置的,则此设置不适用。感谢 jaydisc 启发了我这个事实。答案就在指令中,它控制着错误的显示。php_admin_valuephp_admin_flagdisplay_error

但是,我将帖子的其余部分留在这里,因为根据问题标题,如果不是设置,这将是一个可能的答案。php_admin_value

1.7.x 和 2.x 之间的错误报告差异

无论您的设置如何,Codeigniter 都会在 .http://php.net/manual/en/function.error-reporting.phperror_reportingindex.php

The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.

这属于一个函数系列:http://php.net/manual/en/function.ini-set.php,它们在脚本的持续时间内覆盖 php 指令,包括php_admin_value。error_reportingini_set

对于 1.7.x,(在此处查看旧版本 http://ellislab.com/codeigniter/user-guide/installation/downloads.html),

其中的第一行代码是index.php

error_reporting(E_ALL);

,无论如何都会启用错误(除非稍后通过代码更改设置)。

对于 2.1.4,(https://github.com/EllisLab/CodeIgniter/blob/2.1.4/index.php) 它取决于常量:ENVIRONMENT

/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

评论

0赞 jaydisc 9/27/2013
好吧,我在 VirtualHost 中使用了 php_admin_value,所以我会礼貌地不同意,因为它覆盖了任何单个 php 文件的指令。但无论如何,错误不应该出现在E_ALL上吗?
0赞 xiankai 9/27/2013
@jaydisc我更新了我的答案,以反映覆盖任何服务器指令的事实。此外,如果您担心错误的显示,那么该指令也是相关的。您还应该检查您的设置。error_reporting()display_error
0赞 jaydisc 9/30/2013
不幸的是,php.net/manual/en/configuration.changes.php 不同意你的看法:.但是,您查看display_error的想法确实是正确的。一旦我使用php_admin_flag设置了它,一切都很好。谢谢。不过,由于关于php_admin_value的错误信息,我有点害怕将您的答案标记为正确的答案。Any directive type set with php_admin_value can **not** be overridden by .htaccess or ini_set().
0赞 xiankai 9/30/2013
@jaydisc 没有错误信息,我实际上不知道,谢谢你的链接!我也进一步更新了我的答案以反映这一点。