News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Fabien Potencier's Blog:
Iterator or IteratorAggregate?
June 25, 2010 @ 12:09:44

Following up on two previous posts about iterators, Fabien Potencier is back with one more quick shot on iterator aggregation - a look what using iterator versus iteratoraggregate.

If you have ever used iterators in your code, you have probably implemented the Iterator interface. Objects of a class that implements Iterator can be iterated over with the foreach loop. [...] The IteratorAggregate interface is quite similar [to Iterator] (both interfaces implement Traversable) but creates an external Iterator. But when the iterator is based on an array, creating an external Iterator for this array gives you a more concise and more readable code.

His example code shows how, in implementing and IteratorAggregate, you can grab the instance of the Iterator even if it's based on an array.

1 comment voice your opinion now!
iterator iteratoraggregate comparison traversable interface


blog comments powered by Disqus

Similar Posts

Rafael Dohms' Blog: Iterating over life with SPL Iterators I: Directories

DevShed: Using Directory Iterators and MySQL with Adapter Objects with PHP

Jani Hartikainen's Blog: The problems faced by a common model interface in frameworks

SitePoint PHP Blog: Fun with Array Interfaces

Lorna Mitchell's Blog: Using iterator_to_array() in PHP


Community Events











Don't see your event here?
Let us know!


hack security unittest series opinion language symfony2 code package composer hhvm podcast install facebook framework threedevsandamaybe application introduction release component

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework