【问题标题】:PHP Disable Deprecation Warnings for a Single LinePHP 禁用单行弃用警告
【发布时间】:2022-12-09 12:41:09
【问题描述】:

我目前为我的站点启用了所有错误:

error_reporting(E_ALL);

但是,在 PHP 8.1 中,一些函数现已弃用:

PHP Notice: Function date_sunset() is deprecated in index.php on line 14

由于当前要求,我无法将行更新为未弃用的替代方案。

有没有办法仅针对这一行禁用弃用错误报告?

【问题讨论】:

    标签: php deprecated deprecation-warning php-8 php-8.1


    【解决方案1】:

    作为一种解决方法,您可以像这样包装已弃用的行:

    error_reporting(E_ALL & ~E_DEPRECATED);
    // call deprecated function
    error_reporting(E_ALL);
    

    或者,如果您只想切换已弃用的标志,请使用:

    error_reporting(error_reporting() ^ E_DEPRECATED);
    // call deprecated function
    error_reporting(error_reporting() ^ E_DEPRECATED);
    

    【讨论】:

      猜你喜欢
      • 2018-08-20
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多