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.的第二大投票

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值