ZF-3157: partialLoop helper - check for ArrayObject

Description

There seem to be a bug on SPL level: ArrayObject does not report as Iterator with PHP 5.2.4. It implements ArrayAccess, which indirectly implements Iterator via ArrayIteartor.

This causes a bug when providing an empty ArrayObject to the partialLoop view helper.

Fails:


<?php echo $this->partialLoop('catalog/products.phtml', new ArrayObject()) ?>

Works:


<?php $object = new ArrayObject() ?>
<?php echo $this->partialLoop('catalog/products.phtml', $object->getIterator()) ?>

To fix this in ZF, we need to add an extra check in the partialLoop helper that checks for ArrayObject:


if (!is_array($model) && (!$model instanceof Iterator or !$model instanceof ArrayObject)) { }

Comments

Reported by Matthew:

[http://bugs.php.net/bug.php?id=44793]

Actually, discovered that ArrayAccess does not implement ArrayIterator, but vice versa... meaning that ArrayObject does not implement Iterator. The correct behavior would be to check for Traversable, which would catch both Iterators and ArrayObjects, and would work with foreach().

Scheduling for next mini release.

Resolved in trunk and 1.5 release branch