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

Fre*_*man 2 php error-reporting

我想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);
Run Code Online (Sandbox Code Playgroud)

PHP 版本:7.0.14.

Ple*_*nka 9

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

error_reporting(E_ALL & ~E_USER_DEPRECATED);
//                      ^ this one
trigger_error('Deprecated', E_USER_DEPRECATED);
Run Code Online (Sandbox Code Playgroud)