如何关闭 PHP 通知?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2867057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I turn off PHP Notices?
提问by user198729
Notice: Constant DIR_FS_CATALOG already defined
I've already commented out display_errorsin php.ini, but is not working.
我已经注释掉display_errors的php.ini,但不能正常工作。
How do I make PHP to not output such things to browsers?
如何让 PHP 不向浏览器输出这些东西?
UPDATE
更新
I put display_errors = Offthere but it's still reporting such notices,
我放在display_errors = Off那里,但它仍在报告此类通知,
Is this an issue with PHP 5.3?
这是 PHP 5.3 的问题吗?
Reporting numerous Call Stacktoo..
也报告了许多调用堆栈..
采纳答案by Pekka
You can set display_errorsto 0or use the error_reporting()function.
您可以设置display_errors到0或使用error_reporting()功能。
However, notices are annoying (I can partly sympathize) but they serve a purpose. You shouldn't be defining a constant twice, the second time won't work and the constant will remain unchanged!
然而,通知很烦人(我可以部分地同情)但它们是有目的的。您不应该两次定义常量,第二次将不起作用并且常量将保持不变!
回答by Cristian
From the PHP documentation (error_reporting):
从 PHP 文档(error_reporting):
<?php
// Turn off all error reporting
error_reporting(0);
?>
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);
?>
回答by Paul Salber
For the command line php, set
对于命令行 php,设置
error_reporting = E_ALL & ~E_NOTICE
in /etc/php5/cli/php.ini
在 /etc/php5/cli/php.ini
command phpexecution then ommits the notices.
命令php执行然后忽略通知。
回答by Abhishek Goel
<?php
// Turn off all error reporting
error_reporting(0);
// 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
error_reporting(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);
?>
source http://php.net/manual/en/function.error-reporting.php
回答by vicky mahale
Used This Line In Your Code
在您的代码中使用这一行
error_reporting(E_ALL ^ E_NOTICE);
I think its helf full to you.
我认为它对你来说已经足够了。
回答by Christian Tismer
You are looking for:
您正在寻找:
php -d error_reporting="E_ERROR | E_WARNING | E_PARSE"
回答by jeroen
You can set ini_set('display_errors',0);in your script or define which errors you do want to display with error_reporting().
您可以ini_set('display_errors',0);在脚本中进行设置或定义要显示的错误error_reporting()。
回答by Jonathan Kuhn
by not causing the errors:
通过不引起错误:
defined('DIR_FS_CATALOG') || define('DIR_FS_CATALOG', 'whatever');
If you really have to, then change error reporting using error_reporting() to E_ALL^E_NOTICE.
如果您真的必须这样做,请使用 error_reporting() 将错误报告更改为 E_ALL^E_NOTICE。
回答by algorhythm
I prefer to not set the error_reportinginside my code. But in one case, a legacy product, there are so many notices, that they must be hidden.
我宁愿不在error_reporting我的代码里面设置。但在一种情况下,一个遗留产品,有太多的通知,他们必须隐藏。
So I used following snippet to set the serverside configured value for error_reportingand subtract the E_NOTICEs.
所以我使用以下代码段来设置服务器端配置的值error_reporting并减去E_NOTICEs。
error_reporting(error_reporting() & ~E_NOTICE);
Now the error reporting setting can further be configured in php.inior .htaccess. Only notices will always be disabled.
现在可以在php.ini或 中进一步配置错误报告设置.htaccess。只有通知将始终被禁用。
回答by Nabi K.A.Z.
For PHP code:
对于 PHP 代码:
<?php
error_reporting(E_ALL & ~E_NOTICE);
For php.iniconfig:
对于php.ini配置:
error_reporting = E_ALL & ~E_NOTICE

