Home arrow PHP arrow Using Directory Iterators to Build Loader Apps in PHP

Using Directory Iterators to Build Loader Apps in PHP

Welcome to the final part of an eight-part series on building loader applications in PHP. In this part, we'll improve on the loader class we developed in the previous part by using certain specific functions from the Standard PHP Library (SPL).

  1. Using Directory Iterators to Build Loader Apps in PHP
  2. Review: the previous class loader program
  3. Improving the definition of the Autoloader class using directory iterators
  4. Putting the Autoloader class into action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
July 02, 2009

print this article



Among the bunch of useful features that were incorporated into PHP 5 a long time ago, aside from the improved object model, there's also a set of functions and classes that comprise what's commonly called the Standard PHP Library (SPL).

As you may have heard, this library permits you to perform several clever tasks through a powerful API, such as working with predefined interfaces, traversing arrays and directories easily, loading classes automatically, and so forth. But it's quite possible that at this point you may be wondering what the SPL has to do with building loader applications.

Well, I'm glad you asked, since some of the classes and functions that come packaged with the Standard PHP Library allow you to develop this kind of application in a much more compact and readable way, simplifying the code required for including specified resources and making it easier to create recursive methods.

In the preceding part of this series I explained how to create a loader program that could recursively search for a specified class through the file system on the web server.

While this sample application does its work pretty well when it comes to including classes in a transparent way, there's plenty of room to improve its recursive loading method. And here's where the SPL comes in, since it's possible to use a combination of its "spl_autoload_register()" function and its RecursiveDirectoryIterator class to refactor the method in question and make it shorter and tightrer.

So, with that goal in mind, in this final chapter of the series I'm going to improve the loader class developed in the previous one by incorporating some of the aforementioned SPL functions and classes.

Are you ready to discover the power of using directory iterators for building a more efficient class loading program in PHP 5? Then, don't waste more time in preliminaries; start reading right now!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: