Iterator design pattern in PHP
Iterator design pattern is a software design pattern which provides access to
the elements of an aggregate object sequentially without exposing its
underlying representation. It makes elements appear as a collection of objects.
- Promote to โfull object statusโ the traversal of a collection.
- Polymorphic traversal
PHP implementations
- PHP offers Iterator interface
out of the box. Its SPL library has also a wide variety of
useful iterators. After
understanding the basics of the iterator pattern using these instead of
reinventing the wheel is more convenient.
See also