php压制错误的代码,为什么要压制PHP错误?
你應該積極地養成抑制錯誤的習慣.錯誤是有原因的.相反,在代碼中正確和防御地處理它們,并不斷完善代碼,直到錯誤消失.
你應該做的事情如下:
$conn = mysql_connect($host, $user, $pass);
// Always test to see if your action/connection/whatever was successful
if (!$conn) {
// something went wrong. handle the error
// Display a message for the user, write a message to `error_log()`, whatever's appropriate
}
else mysql_select_db($dbname);
在生產系統上,您永遠不應該顯示錯誤,因為它可能會泄露您的代碼和數據庫的詳細信息.相反,在php.ini或運行時關閉display_errors:
// In development and production, make sure all errors are reported
error_reporting(E_ALL & E_STRICT);
// In development show all errors on screen so you handle them as they occur
ini_set('display_errors', 1);
// In production turn them off
ini_set('display_errors', 0);
事實上,使用@的錯誤抑制是PHP糟糕練習in this classic question.的第二大投票
總結
以上是生活随笔為你收集整理的php压制错误的代码,为什么要压制PHP错误?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angular2 php 教程,有关Ma
- 下一篇: php安卓交互安全,php结合安卓客户端