2013-01-18 66 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; 

这不会解决你的错误,但要当你修复它您的错误列表清晰。