Thomas Weinart: What Iterators Can Do For You
Note: This article was originally published at PHPDeveloper on 2 August 2012.
Thomas Weinert has a new post to his site showing some of the things that iterators can do for you (including working with arrays and aggregation).
Basically Iterators provide a list interface for an object. Like all interfaces they are a contract how something can be used. If you use an interface it is not relevant how it is implemented - the implementation logic is encapsulated. It is of course relevant on the integration level. A bad implementation can impact the performance of you application. Even an good implementation may need special resources (like a database). But all this does not impact how you use it. Your code using the object with the Iterator interface stays the same.