2013-01-18 51 views
4

我發現在我的系統上「error_reporting」被關閉。所以我打開了它(E_ALL),現在我有很多錯誤。好主意忽略錯誤?

如果你有興趣在我的錯誤:

Notice: Undefined index: page in …path/file.php on line 22 
Notice: Undefined offset: 1 in …path/file.php on line 49 
Notice: Undefined offset: 2 in …path/file.php on line 57 
Notice: Undefined offset: 3 in …path/file.php on line 58 
Notice: Undefined variable: out in …path/file.php on line 85 
Notice: Undefined variable: out in …path/file.php on line 109 
Notice: Use of undefined constant M_DESCRIPTION - assumed 'M_DESCRIPTION' in …path/file.php on line 181 
Notice: Use of undefined constant GA_TRACKER - assumed 'GA_TRACKER' in …path/file.php on line 291 
Notice: A session had already been started - ignoring session_start() in …path/file.php on line 12 
Notice: Undefined variable: attributes in …path/file.php on line 86 
Notice: Undefined variable: li in …path/file.php on line 129 
Notice: Undefined index: breakafterlabel in …path/file.php on line 175 
Notice: Undefined index: afterlabel in …path/file.php on line 167 
Notice: Undefined index: attributes in …path/file.php on line 188 
Notice: Undefined index: value in …path/file.php on line 191 
Notice: Undefined index: for in …path/file.php on line 163 
Notice: Undefined index: attributes in …path/file.php on line 249 
Notice: Undefined index: value in …path/file.php on line 299 
Notice: Undefined variable: out in …path/file.php on line 109 
Notice: Undefined offset: 0 in …path/file.php on line 418 
Notice: Undefined index: maxlength in …path/file.php on line 368 
Notice: Undefined index: accept in …path/file.php on line 372 
Notice: Undefined variable: out in …path/file.php on line 93 
Notice: Undefined index: accept in …path/file.php on line 378 
Notice: Undefined index: title in …path/file.php on line 379 
Notice: Undefined index: accept in …path/file.php on line 402 
Notice: Undefined index: fp in …path/file.php on line 624 
Notice: Undefined variable: alert_msg in …path/file.php on line 246 
Notice: Undefined variable: returner in …path/file.php on line 87 
Notice: Undefined index: body in …path/file.php on line 309 
Notice: Undefined variable: out in …path/file.php on line 81 
Notice: Undefined variable: defaults in …path/file.php on line 121 

首先我想:「哦,你最好再關閉」,但我不知道後果!

所以非常簡單的問題是:如果我忽略了所有的錯誤,這是否重要?

+11

你應該修復它們 –

+0

你能解釋一下爲什麼嗎?或者你有鏈接?因爲我感興趣爲什麼我應該修復它們。後果是什麼? –

+2

@JohnDoeSmith [「任何可能出錯,都會出錯的地方。」](http://en.wikipedia.org/wiki/Murphy's_law) – Leri

回答

5

在開發環境中,最好使用error_reporting(E_ALL),以便您可以看到通知。這鼓勵你有更高的編碼標準。

運行現場網站時,您必須有display_errors off,但記錄您的錯誤(就像您正在做的那樣)。

這樣,您只會看到有意義的錯誤,而不僅僅是「Notice:Undefined ...」。如果網站已經完成,你應該花一些時間重構你的代碼,長期的好處將是值得的。

+1

在生產環境中,我更喜歡'error_reporting(E_ALL) ','display_errors = Off','log_errors = On'和'error_log =/some/file/errors.log' –

1

答案是:不! 忽略錯誤可能會導致意外的行爲。另外它可能會減慢程序/腳本的執行速度。所以你最好不要忽略,但要解決它們。

做的更詳細:在大多數情況下,Undefined offset錯誤沒有問題,Use of undefined constant常數或失敗的session_start可能是危險的。

+1

如果你記錄他們,你可能遇到如下問題:[2bits.com](http:// 2bits .com/drupal/avoid-excessive-disk-writes-avoid-php-errors-your-code.html) 他們在哪兒說:「道德故事:首先不要有php錯誤和通知。 「 – mosch

-1

您應該注意錯誤和警告。 他們是你說你在做錯了事。

這些錯誤在開發環境中非常有用。 但是,當您釋放代碼時,最好禁用它們。

3

如果你只是想暫時隱藏一些信息錯誤,使用@:

echo @$undefined; 
@session_start; 

這不會解決你的錯誤,但要當你修復它您的錯誤列表清晰。