日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

php压制错误的代码,为什么要压制PHP错误?

發布時間:2025/3/20 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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错误?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。