Home arrow PHP arrow Developing a Recursive Loading Class for Loader Applications in PHP

Developing a Recursive Loading Class for Loader Applications in PHP

Welcome to the third part of an eight-part series on building loader applications in PHP. In the tutorials that comprise this series you’ll find numerous examples aimed at demonstrating how to create small, yet efficient, resource loader classes, not only by taking advantage of PHP includes, but the handy “__autoload()” magic function and the Standard PHP Library (SPL) as well.

  1. Developing a Recursive Loading Class for Loader Applications in PHP
  2. Review: building a basic file loading class with PHP 5
  3. Defining a class with recursive file searching capabilities
  4. Defining the recursive load() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
June 18, 2009

print this article



Developing PHP programs whose main task is to dynamically include files required by a specific application isn’t as difficult as it may seem at first sight. In these cases, the logic that drives those programs is implemented around the set of “include()/include_once()/require()/require_once()” native PHP functions, which are pretty familiar to many developers having an average background on this language.

So, if you’re searching for an approachable guide that shows you how to build file loading applications in PHP 5, without having to pull your hair desperately, then hopefully this group of articles will give you the material you're looking for.  

By this time, you’re well aware of the goal of this article series, so I’d like to spend a few moments refreshing the concepts I explained in the previous part. In that article, I developed a basic loader class which was capable of including a specified file without having to create any instances of the class. This capacity was implemented by defining a static loading method, which was in reality the class’s workhorse, since it acted like a wrapper for the “require_once()” PHP function. 

While this file loading class in its current incarnation does a pretty good job, it lacks an important feature that could be added with relative ease. It cannot perform a recursive search through the web server’s file system, and afterward include a specified file within a given application. 

Essentially, the class would be passed a starting path to look for, and from that point onward it would recursively traverse the subfolders, until finding the targeted file. That’s an ability found in many popular PHP applications available nowadays, and in the next few lines I’m going to explain how to implement it, based mostly on the structure of the loader class created in previous chapter of the series. 

Now, let’s start learning how to build a loading class that will have recursive file searching capabilities. Let’s get going!

>>> 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: