dpqjvoq9033 2016-10-12 15:41
浏览 43
已采纳

PHP:尽管禁用了所有错误,但仍会在页面上显示copy()错误消息

I have:

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);

It seems to work but when I use copy() function and try to copy to directory with denied access the error is displayed on the page itself. I don't need it. But I can't intercept copy()'s errors. I tried error_get_last() and try...catch (Exception $e) but still can't intercept it? How can I disable showing copy errors on page and how to intercept them in code?

  • 写回答

2条回答 默认 最新

  • donglie1898 2016-10-12 15:50
    关注

    from runtime it is better (and more reliable) to use:

    error_reporting(0);
    

    see: http://php.net/manual/en/function.error-reporting.php for more info.

    also you can suppress any errors regarding of reporting level by prefixing expression with @:

    @copy(...)
    

    see: http://php.net/manual/en/language.operators.errorcontrol.php for more info, also note what this cause a performance drop and causes expression to return boolean false if error occured, regardless of its original return type.

    Worth noting:

    If you are using nginx+php-fpm (or similar) ini values may be overriden in php-fpm's pool configuration.

    If you are using apache+mod_php ini values may be overriden in .htaccess file.

    Check that, before resolving to error_reporting(0), turning off error_reporting completely is not what you should do, as this may lead to broken logic (many popular libraries and frameworks rely on error reporting by setting handlers to traslate errors to exceptions).

    In terms of portability use of error suppressing operator is preferred, dispite its affect on performance.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大