用户
 找回密码
 入住 CI 中国社区
搜索
查看: 9050|回复: 5
收起左侧

[优化] 关闭CI的php notice

[复制链接]
发表于 2010-2-26 17:37:31 | 显示全部楼层 |阅读模式
用CI的时候,如果一个变量没有值,CI就会提示 Undefined,用PHP的开发的人都知道,定义PHP的变量是不需要初始化任何的值,看这notice真烦人,决定关掉它,开始先搜 A PHP Error was encountered 只在error目录中找到error_php.php,不是想要的结果,这文件只是模板,再搜文件名:error_php,在system/libraies中的Exceptions中发现

    /**
     * Native PHP error handler
     *
     * @access  private
     * @param   string  the error severity
     * @param   string  the error string
     * @param   string  the error filepath
     * @param   string  the error line number
     * @return  string
     */
    function show_php_error($severity, $message, $filepath, $line)
    {   
        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
     
        $filepath = str_replace("\\", "/", $filepath);
         
        // For safety reasons we do not show the full file path
        if (FALSE !== strpos($filepath, '/'))
        {
            $x = explode('/', $filepath);
            $filepath = $x[count($x)-2].'/'.end($x);
        }
         
        if (ob_get_level() > $this->ob_level + 1)
        {
            ob_end_flush();  
        }
        ob_start();
        include(APPPATH.'errors/error_php'.EXT);  
        $buffer = ob_get_contents();
        ob_end_clean();
        echo $buffer;
    }
找到include(APPPATH.'errors/error_php'.EXT); 这行,把它注释掉,就OK了


本文来自黄俊
发表于 2010-4-11 10:13:31 | 显示全部楼层
这个不错
发表于 2010-4-12 13:29:09 | 显示全部楼层
初始化变量的确是个好习惯
有助于你的程序健壮 安全
发表于 2010-7-9 21:42:08 | 显示全部楼层
去改index.php就可以了。。设置错误级别
发表于 2016-1-23 15:55:26 | 显示全部楼层
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); 将index.php里面的development改成production模式就行了。记得重启服务器才行啊。
发表于 2016-1-25 12:45:15 | 显示全部楼层
不建议关掉这个,变量都初始化是一个非常好的编程习惯。
好习惯的养成不容易。

本版积分规则