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 - PHP Tutorial
From the course: Learning the Standard PHP Library
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Filtering a directory with GlobIterator5m 14s
-
(Locked)
Using regular expressions to filter directories with RegexIterator3m 49s
-
(Locked)
Extracting data from XML with RegexIterator and SimpleXML6m 25s
-
(Locked)
Specifying a range of items with LimitIterator4m 21s
-
(Locked)
Creating a custom filter with CallbackFilterIterator5m 6s
-
(Locked)
Creating a recursive callback filter5m 42s
-
(Locked)
Extending FilterIterator to create a reusable filter5m 10s
-
(Locked)
Creating a custom filter with RecursiveFilterIterator4m 48s
-
(Locked)
Overriding the RecursiveFilterIterator constructor5m 16s
-
(Locked)
Using ParentIterator to find elements that have children3m 59s
-
(Locked)
-
-
-
-
-