This works correctly, by passing $this
as a variable I don't need to worry about colliding with $this->object
or scope issues.
/**
* Public wrapper for Protected getArray()
*
* @return arrau
*/
public function toArray()
{
return $this->getArray($this->object);
}
/**
* Take an ArrayObject and turn it into an associative array
*
* @param ArrayObject $obj
*
* @return array
*/
protected function getArray($obj)
{
$array = array(); // noisy $array does not exist
$arrObj = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($arrObj as $key => $val) {
$val = (is_array($val) || is_object($val)) ? $this->getArray($val) : $val;
$array[$key] = $val;
}
return $array;
}