To make an object iterable and to make it appear like a collection of objects.
- to process a file line by line by just running over all lines (which have an object representation) for a file (which of course is an object, too)
Standard PHP Library (SPL) defines an interface Iterator which is best suited for this! Often you would want to implement the Countable interface too, to allow count($object)
on your iterable object
You can also find these code on GitHub
Book.php
Book.php
BookList.php
BookList.php
BookListIterator.php
BookListIterator.php
BookListReverseIterator.php
BookListReverseIterator.php
Tests/IteratorTest.php
Tests/IteratorTest.php