use*_*729 114 php error-handling constants
Notice: Constant DIR_FS_CATALOG already defined
Run Code Online (Sandbox Code Playgroud)
我已经注释掉display_errors的php.ini,但不能正常工作.
如何让PHP不向浏览器输出这些内容?
UPDATE
我放在display_errors = Off那里,但它仍在报告此类通知,
这是PHP 5.3的问题吗?
报告众多调用堆栈 ..
Cri*_*ian 228
从PHP文档(error_reporting):
<?php
// Turn off all error reporting
error_reporting(0);
?>
Run Code Online (Sandbox Code Playgroud)
该功能的其他有趣选项:
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
Pek*_*ica 75
您可以设置display_errors到0或使用error_reporting()功能.
但是,通知很烦人(我可以部分同情),但它们是有目的的.你不应该两次定义常量,第二次不起作用,常量将保持不变!
小智 31
对于命令行php,请设置
error_reporting = E_ALL & ~E_NOTICE
Run Code Online (Sandbox Code Playgroud)
在 /etc/php5/cli/php.ini
命令php执行然后省略通知.
Abh*_*oel 21
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
来源http://php.net/manual/en/function.error-reporting.php
vic*_*ale 11
在您的代码中使用此行
error_reporting(E_ALL ^ E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
我觉得它的遗产很丰富.
我宁愿不在error_reporting我的代码里面设置。但在一种情况下,一个遗留产品,有太多的通知,他们必须隐藏。
所以我使用以下代码段来设置服务器端配置的值,error_reporting但减去E_NOTICEs。
error_reporting(error_reporting() & ~E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
现在可以在php.ini或 中进一步配置错误报告设置.htaccess。只有通知将始终被禁用。
对于 PHP 代码:
<?php
error_reporting(E_ALL & ~E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
对于php.ini配置:
error_reporting = E_ALL & ~E_NOTICE
Run Code Online (Sandbox Code Playgroud)
我最近发现了这个技巧。在行的开头敲击 @ 可能会产生警告/错误。
就像施了魔法一样,它们消失了。
小智 5
您正在寻找:
php -d error_reporting="E_ERROR | E_WARNING | E_PARSE"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
402009 次 |
| 最近记录: |