O'Reilly logo

Pro PHP: Patterns, Frameworks, Testing and More by Kevin McArthur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 10SPL Iterators

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 Iterator or IteratorAggregate interface.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required