not sure if cast works here, otherwise we can check instanceof \Iterator
and use http://php.net/manual/en/function.iterator-to-array.php if its
an iterator.