From the course: Learning the Standard PHP Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Overriding the RecursiveFilterIterator constructor

Overriding the RecursiveFilterIterator constructor - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

Overriding the RecursiveFilterIterator constructor

- We've created a class called Filter Images, that extends Recursive Filter Iterator. It produces the results we want, but the class would be more flexible if the constructor accepted an argument listing the extensions we want to search for. Overwriting the constructor involves a little more work with the Recursive Iterator. Incidentally, if you need a copy of this file, you can find it in recursive_filter02.php in the Chapter 3 folder of the exercise files. So, let's rename the class Filter By Extension. Then, inside the class definition, we need to create a protective property for extensions. Then, we need to override the constructor method. That's public function double-underscore construct, and we need to pass it to arguments. The first one is the iterator, and we can use code hinting for the iterator. It needs to implement the Recursive Iterator interface. So, Recursive Iterator and we'll call it Iterator. The second document will be the extensions we're looking for. So in the…

Contents