2012-07-13 127 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