One of the nice things about iterators is the ability to shove them into other iterators, allowing you to wrap their functionality in other functionality to return a more precise result set. Take for example the idea that we want to read a directory to list only the images inside of it. There are two main ways to do this, via opendir / readdir functions and via FilesystemIterator objects.
Going the FilesystemIterator route, one common way seems to be extend another class called FilterIterator which allows you to customize a filter based on you overwriting a method called accept().
Armed with that class, we could have a bit of code like this…
Which is fine, but if I need to use this ImageFilterIterator multiple times in a code base, not only does that look clumsy but it is super annoying to type. We can clean that up a bit if we extend FilterIterator a little more. Instead of just overriding the accept method, we will also override the __construct.
Now the code that needs this functionality can be reduced down to…
This I find much more tolerable – we have the full power of the FilterIterator running a FilesystemIterator without having to specify that every time we want to read the image directory.

