V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wfdaj
V2EX  ›  PHP

请问,我该如何设置 ini_set display_errors 的值?

  •  
  •   wfdaj · 2021-04-05 00:40:40 +08:00 · 1825 次点击
    这是一个创建于 1089 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Debug 类里这样写的:

    /**
     * 是否显示错误,默认不显示
     */
    public static function displayErrors($status = false)
        {
            if ($status) {
                // 报告所有 PHP 错误
                ini_set('display_errors', 1);
                error_reporting(E_ALL);
            }
    
            // self::error_handler();
        }
    

    然后这样调用就无效

    Debug::displayErrors(1);
    

    但我在页面里直接这样用可以正常设置:

    ini_set('display_errors', 1);
    
    7 条回复    2021-04-06 08:51:03 +08:00
    lijialong1313
        1
    lijialong1313  
       2021-04-05 02:13:43 +08:00
    没懂你的意思,建议发完整代码,是怎么设置不行怎么行。

    https://www.php.net/manual/zh/errorfunc.configuration.php
    wfdaj
        2
    wfdaj  
    OP
       2021-04-05 08:18:25 +08:00 via Android
    @lijialong1313 就是在首页 Debug::displayErrors(0); 这样调用后,输出 display_errors 的值还是 1 。
    Oceanhime
        3
    Oceanhime  
       2021-04-05 09:46:03 +08:00
    确定 if 里面的语句真的被执行了吗
    seth19960929
        4
    seth19960929  
       2021-04-05 09:47:42 +08:00
    传入 0 输出值还是 1 的原因可能是你的 php.ini 设置的默认值是 1

    所以不能判断 $status
    而是 ini_set('display_errors', $status);
    Oceanhime
        5
    Oceanhime  
       2021-04-05 09:48:11 +08:00
    @wfdaj 按正文里面的代码逻辑来看 Debug::displayErrors(0) 确实不会更改 display_errors 的值
    因为你只写了 $status 时候的操作, 没有写 !$status 时候的操作
    lijialong1313
        6
    lijialong1313  
       2021-04-05 13:26:17 +08:00
    @wfdaj 你调用 0 都没设置成 error 0
    应该是类似:
    public static function displayErrors($status = false)
    {
    if ($status) {
    // 报告所有 PHP 错误
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    }
    else{
    ini_set('display_errors', 0);
    }

    // self::error_handler();
    }
    wfdaj
        7
    wfdaj  
    OP
       2021-04-06 08:51:03 +08:00
    感谢各位的帮助,我再试试。🙏
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1273 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 23:29 · PVG 07:29 · LAX 16:29 · JFK 19:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.