【问题标题】:How to disable deprecated warnings in runtime php?如何在运行时 php 中禁用已弃用的警告?
【发布时间】:2018-08-20 14:14:50
【问题描述】:

我想在运行时禁止来自此trigger_error('Deprecated', E_USER_DEPRECATED); 的警告。根据我的阅读,我可以使用error_reporting(E_ALL & -E_USER_DEPRECATED & -E_DEPRECATED);。但这不起作用。如果error_reporting 使用error_reporting(0) 可以正常工作,我试过了。这行得通。我错过了什么?我没有找到另一种方法来解决我的问题。并且没有注意到这种方式对其他人不起作用。

我的代码不会抑制已弃用的警告:

error_reporting(E_ALL & -E_USER_DEPRECATED);
trigger_error('Deprecated', E_USER_DEPRECATED);

php 版本:7.0.14.

【问题讨论】:

  • 我想你想要的是波浪号,试试error_reporting(E_ALL & ~E_DEPRECATED);

标签: php error-reporting


【解决方案1】:

error_reporting() 的值存在语法错误。要排除某些错误,您需要使用波浪号 ~ 而不是破折号 -

error_reporting(E_ALL & ~E_USER_DEPRECATED);
//                      ^ this one
trigger_error('Deprecated', E_USER_DEPRECATED);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 2015-05-05
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2020-03-29
    相关资源
    最近更新 更多