Iterator Design Pattern in PHP
Iterator pattern is 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 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.
Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.