As you learned in the previous chapter, in order to control looping with the
foreach statement, all objects must implement the
Traversable interface. But, the
Traversable interface is an internal-only interface, so trying to implement it in your userland classes will simply result in an error. To actually implement looping of your objects, you must implement
Traversable via the
For some uses, implementing
Iterator might be enough, but when you need more functionality, you can choose from several extended iterator interfaces, which allow for seekable, recursive, aggregated, or even cached access.
Along with providing the capability to iterate objects, the SPL also contains a number ...