php压制错误的代码,为什么要压制PHP错误?
你應(yīng)該積極地養(yǎng)成抑制錯(cuò)誤的習(xí)慣.錯(cuò)誤是有原因的.相反,在代碼中正確和防御地處理它們,并不斷完善代碼,直到錯(cuò)誤消失.
你應(yīng)該做的事情如下:
$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);
在生產(chǎn)系統(tǒng)上,您永遠(yuǎn)不應(yīng)該顯示錯(cuò)誤,因?yàn)樗赡軙?huì)泄露您的代碼和數(shù)據(jù)庫的詳細(xì)信息.相反,在php.ini或運(yùn)行時(shí)關(guān)閉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);
事實(shí)上,使用@的錯(cuò)誤抑制是PHP糟糕練習(xí)in this classic question.的第二大投票
總結(jié)
以上是生活随笔為你收集整理的php压制错误的代码,为什么要压制PHP错误?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angular2 php 教程,有关Ma
- 下一篇: resoult在python啥意思,py