嘿伙计们,我有一个方法应该回调并递归地将一个Arrayobject
转换为关联数组,不幸的是我遇到了一个致命错误
PHP Fatal error: Call to undefined method ArrayObject::toArray()
这是我的方法
/**
* Take an ArrayObject and recursively turn it into an array
*
* @param bool $recursion
*
* @return array
*/
public function toArray($recursion = false)
{
// just in case the object might be multidimensional
if (true === $this->object) return $this->object->getArrayCopy();
return array_map( function($item)
{
return is_object($item) ? $item->toArray(true) : $item;
}, $this->object->getArrayCopy() );
}
这是一个示例ArrayObject
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[profile] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[list] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[location] =>
[network_name] =>
[interests] =>
[last_name] =>
[url] =>
[significant_other] =>
[network_domains] =>
[contact] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[im] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[provider] =>
)
)
[email_addresses] =>
)
)
)
)
)
)
[messages] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[list] => Array
(
[0] => foo
[1] => bar
[2] => baz
)
)
)
[groups] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
[users] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
)
)