我需要设置我的PHP脚本在顶部禁用错误的严格标准报告。

有人能帮忙吗?

有帮助吗?

解决方案

是否要禁用错误报告,或者只是防止用户看到它?它通常是记录错误是一个好主意,即使是在生产现场。

# in your PHP code:
ini_set('display_errors', '0');     # don't show any errors...
error_reporting(E_ALL | E_STRICT);  # ...but do log them

他们将被记录到你的标准系统日志,或使用error_log指令指定正是您想要的错误去了。

其他提示

有关没有错误。

error_reporting(0);

或只是不严格

error_reporting(E_ALL ^ E_STRICT);

如果你想再次显示所有的错误,使用

error_reporting(-1);

所有上述解决方案是正确的。但是,当我们在谈论一个正常的PHP应用程序,他们必须包含在每一个页面,它需要。为了解决这一点的方法,是通过在.htaccess根文件夹。 只是用来掩饰错误。 [把followling线中的一条在该文件中]

php_flag display_errors off

或者

php_value display_errors 0

接下来,以设置错误报告

php_value error_reporting 30719

如果你想知道的价值30719怎么来的,E_ALL(32767),E_STRICT(2048)实际上是持有数值和常数(32767 - 2048 = 30719

的默认值的的error_reporting 标志的 E_ALL&〜E_NOTICE 如果在php.ini未设置。 但是,在一些安装(尤其是安装针对开发环境),有 E_ALL | E_STRICT 设置为<强>此标志的值(在开发过程中,这是在推荐值为)。在某些情况下,特别是当你要运行一些开源项目,其开发之前PHP 5.3时代,尚未与PHP 5.3中定义的最佳实践更新,在开发环境中,你可能会碰到一些让像你这样的消息得到。应付了这方面的情况,最好的方法,是设置只的 E_ALL 为的值的的error_reporting 标志,无论是在的的php.ini 或在的(可能在一个前端控制器像web的根的index.php如下:

if(defined('E_STRICT')){
    error_reporting(E_ALL);
}

在php.ini中设置:

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

<强> WordPress的

如果你在WordPress环境中工作,WordPress的设置在文件中的错误水平WP-包括在功能wp_debug_mode() / load.php。所以,你必须改变等级后,此函数被调用(在文件中未检查到的git因此只有发展),或任何直接修改error_reporting()呼叫

我没有看到一个答案那是干净的,适合生产就绪型软件,所以这里有云:

/*
 * Get current error_reporting value,
 * so that we don't lose preferences set in php.ini and .htaccess
 * and accidently reenable message types disabled in those.
 *
 * If you want to disable e.g. E_STRICT on a global level,
 * use php.ini (or .htaccess for folder-level)
 */
$old_error_reporting = error_reporting();

/*
 * Disable E_STRICT on top of current error_reporting.
 *
 * Note: do NOT use ^ for disabling error message types,
 * as ^ will re-ENABLE the message type if it happens to be disabled already!
 */
error_reporting($old_error_reporting & ~E_STRICT);


// code that should not emit E_STRICT messages goes here


/*
 * Optional, depending on if/what code comes after.
 * Restore old settings.
 */
error_reporting($old_error_reporting);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top