Modifying Your Class

You've upgraded the syntax of your code to PHP 5 standards, but you still need to improve the functionality of your DirectoryItems class. This involves rewriting the constructor to make it do a bit more work and adding more methods to the class. The additional methods will improve the flexibility of the class by filtering for specific file types.

Reconstructing the Constructor

Currently, the constructor for the DirectoryItems class uses an array to keep track of filenames. The underutilization of the capabilities of an array suggest changes to the constructor.

Arrays in PHP are very flexible—they can be either numerical or associative. The current constructor simply stores the filenames in a numeric array, but if you ...

Get Object-Oriented PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.