我正在尝试从一个对象中调用我的对象的方法之一array_map
匿名函数。到目前为止,我收到了预期的错误:
致命错误:不在对象上下文中时使用 $this...
我知道为什么我会收到此错误,我只是不知道如何实现我想要的目标...有人有任何建议吗?
这是我当前的代码:
// Loop through the data and ensure the numbers are formatted correctly
array_map(function($value){
return $this->some_method($value,'value',false);
},$this->mssql->data[0]['results'][0]);
您可以使用“use”关键字告诉函数“关闭”$this 变量
$host = $this;
array_map(function($value) use ($host) {
return $host->some_method($value,'value',false);
},$this->mssql->data[0]['results'][0]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)