繁体   English   中英

PHP error_reporting开启或关闭

[英]PHP error_reporting either on or off

我无法在短时间内关闭已弃用的警告。 它们来自一个我不得不工作一段时间的垃圾堆脚本,其中过度使用了preg_replace和/ e修饰符。 与其去修复所有执行此操作的位置,不如在我正在处理时关闭不建议使用的警告,这是一个更好的主意。

奇怪的是,该脚本开头的error_reporting函数似乎仅具有“打开/关闭”效果。 也就是说,我可以使用error_reporting(0)完全关闭报告功能,并且可以使用error_reporting(E_ALL)类的功能将其全部打开。 但是,使用以下任何选项均无效。 我仍然可以在页面顶部看到100多个不推荐使用的警告。

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(E_ALL & ~E_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

我已验证我的php.ini文件设置为E_ALL & ~E_DEPRECATED) (24575),并且它在phpinfo()中显示为此类。 项目根目录中的.htaccess文件为空。 我什至不知道为什么还要有一个。

PHP 5.5.9-1ubuntu4.4

有任何想法吗?

我要说的是,可能包含的另一个页面或脚本将error_reporting设置为另一个值。 您可以不带参数调用error_reporting()以获取当前值。 将其设置为某种值,并在包含其他文件后检查该值是否未更改。

error_reporting(E_ALL | E_STRICT); 

只是说“嘿,记录这些错误/警告/通知”

我认为您将需要-

ini_set('display_errors', '0');

试试看。

解决方案:

ini_set("display_errors",'off');

在您的php脚本中使用它。它将隐藏警告出现在您的页面中。

Other interesting options for that function:

<?php

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// For PHP >=5.3 use: E_ALL & ~E_NOTICE

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM