private static function _removeRecursion(&$object, $stack = array()) { if ((is_object($object) || is_array($object)) && $object) { if ($object instanceof Traversable) { $object = "***ITERATOR***"; } else { if (!in_array($object, $stack, true)) { $stack[] = $object; foreach ($object as &$subobject) { self::_removeRecursion($subobject, $stack); } } else { $object = "***RECURSION***"; } } } return $object; }