dpno17028 2018-03-12 14:07
浏览 129
已采纳

如何在运行时php中禁用已弃用的警告?

I want to supress warning from this trigger_error('Deprecated', E_USER_DEPRECATED); in runtime. From I have read I can use error_reporting(E_ALL & -E_USER_DEPRECATED & -E_DEPRECATED);. But that does not work. I tried if error_reporting works in general by using error_reporting(0). This works. What did I miss? I did not find another way to solve my problem. And did not notice that this way does not work for someone else.

My code which does not suppress deprecated warning:

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

Php version: 7.0.14.

  • 写回答

1条回答 默认 最新

  • dsgsdg206050 2018-03-12 14:17
    关注

    You have a syntax error in the value for error_reporting(). To exclude certain errors you need to use the tilde symbol ~ instead of the dash -:

    error_reporting(E_ALL & ~E_USER_DEPRECATED);
    //                      ^ this one
    trigger_error('Deprecated', E_USER_DEPRECATED);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?