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


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

我有两个相同的 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,这似乎覆盖了配置.php定义的开发环境设置,该设置将error_reporting设置为 E_ALL。

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

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

两者输出相同:

-1  
5.3.3-7+squeeze17

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

在应用程序/配置/配置中.php在 2.1.4 中(错误未显示(:

$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_admin_valuephp_admin_flag 设置的,则这不适用。感谢jaydisc启发我这个事实。答案就在display_error指令中,它控制着错误的显示。

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

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

无论您的error_reporting设置如何,Codeigniter 都会在 index.php 中覆盖它。 http://php.net/manual/en/function.error-reporting.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.

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

对于 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.');
    }
}