首页 > 解决方案 > 在 PHP 类中,调用内部方法显示错误消息

问题描述

我正在尝试使用以下函数小写多维数组的所有键。下面的代码来自一个类。我看到当我to_lower()在类中使用此方法时,它向我显示错误消息:

该网站遇到了技术难题。请检查您的站点管理员电子邮件收件箱以获取说明。

但是,如果我在没有类的情况下测试这个方法/函数,它就很好用!谁能告诉我为什么会这样?

public function to_lower($arr)
{
    return array_map(function($item){
        if(is_array($item))
            $item = to_lower($item);
        return $item;
    },array_change_key_case($arr));
}

public function logout_redirect_to()
{

    $user = $this->current_user;
    $options = $this->options['wpll_general_settings'];
    echo '<pre>';
    print_r($this->to_lower($options)); // why this line is showing error message? 
    wp_die();
    /// more code here....
}

标签: php

解决方案


你的递归调用是错误的

public function to_lower($arr)
    {
        return array_map(function($item){
            if(is_array($item))
                $item = $this->to_lower($item); //Your recursive call is wrong
            return $item;
        },array_change_key_case($arr));
   }

如需调试帮助,请在本地开发服务器上显示您的 php 错误或使用 error_log 获取有关错误的详细信息 :)


推荐阅读