Countable
Though not strictly part of the Iterator design pattern (and definitely distinct from the Iterator interface of the SPL Library), implementing the Countable interface is complementary functionality.
Partial Listing: /fw/foundation/IWIterator.php
abstract class IWIterator implements Iterator, Countable { protected $array; // only method required for the Countable interface function count() { return count($this->array); } ... }
Now I can use the count() function on both a PHP array and an IWArray instance. For the example below, I could write count($php_array) and count($iw_array) and both will work as expected.
Pseudo Listing: /adhoc/countable.php
// Retrieve data in the form of an array $select = new ORMSelect('category'); $categories = ORMFactory::instanceArray('category'); // returns an IWArray object // The count() function works on the collection $num_categories = count($categories);