2012-07-13 97 views
0

在PHP中,您如何使它在使用error_reporting()函数时仅显示错误。目前IIS PHP应用程序被设置为'生产机器'。如果将其更改为开发机器,即使没有error_reporting(),它也会打印出所有错误。PHP按需错误报告

回答

1

我得到了我想要使用的行为:

​​
0

为你做

error_reporting(0); 

工作?

1

在您的“生产机器”上,您可以直接在PHP脚本中打开或关闭error_reporting ...。

您也可以在您的服务器上的php.ini文件中找到此设置以设置默认值。

<?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 
// This is the default value set in php.ini 
error_reporting(E_ALL^E_NOTICE); 

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

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

?> 
2

error_reporting可能由您的应用程序设置并覆盖php.ini设置。

无论如何,你应该从来没有把它关掉。

相反,在php.ini更改display_errorsOff,或者在你的代码:

ini_set('display_errors', 0); 
+0

我已在php.ini中设置使用error_reporting到默认的'E_ALL&〜DEPRECATED'和display_errors设置为Off。但是当我把error_reporting(-1);在错误填充的php文件的顶部,它只是显示一个空白页面。 – Ray 2012-07-13 19:33:00

+0

尽管我的日志文件中包含错误,但在开发过程中将它们放在页面上会更方便。 – Ray 2012-07-13 19:39:11

+0

@Raymond:不确定你想要什么。你想展示或隐藏它们?你能澄清吗? – netcoder 2012-07-13 19:48:57