php - 在 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....
}
解决方案
你的递归调用是错误的
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 获取有关错误的详细信息 :)
推荐阅读
- java - JPA/CriteriaBuilder 忽略 Double 的小数部分
- php - 在 Azure 上存储不带 Blob 存储的映像
- unity3d - 在 Unity 中构建后 Google AdMob 测试广告未显示
- stored-procedures - 基本存储过程 - 为什么这不起作用?
- typescript - 如何在组合 api + typescript 中重置/清除接口属性?
- mongodb - 当集合在特定时间范围内未更新时,如何使用 MongoDB Atlas 触发器向用户发送自动电子邮件
- parse-platform - 如何否定 Parse 的 API (Back4App) 中的查询?具体来说,我如何让一切都没有关系?
- javascript - ReactJS fetch 不返回错误并返回不正确的数据
- python - 使用列和索引将抓取的列表转换为熊猫数据框
- java - Tomcat 上的 Spring 应用程序 - 无法启动上下文路径 /web-customer-rest-demo 中的应用程序