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

Defining a class with recursive file searching capabilities - 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



As I stated in the previous segment, it’s possible to build a file loading class that has the ability to look for a targeted file recursively. To create a class with this capability, first I’m going to define its basic structure along with a few setter and getter methods, which will be responsible for setting and getting the file for which to search, and for performing the same tasks with the starting file path. 

If this brief description sounds a bit confusing to you, the following code sample should help to dissipate your doubts. Take a look at it:


// define a recursive loader class

class Loader


private $file = '';

private $path = '';

// constructor (not implemented)

public function __construct(){}


// set file to load

public function set_file($file)


$this->file = $file;



// get file to load

public function get_file()


return $this->file;



// set path to load file

public function set_path($path)


$this->path = $path;



// get path to load file

public function get_path()


return $this->path;




As you can see, the above “Loader()” class has some simple methods, apart from the constructor, for setting and getting the file that needs to be included, and for establishing and retrieving the path from which to start searching the file. 

These setters and getters are very easy to understand, so I’m not going to spend more time discussing how they work. But wait a minute! Didn’t I say at the beginning of this section that my purpose here was building a file loader class that is capable of including a specified file through a recursive search? Yes, I did. 

But this functionality needs to be implemented by means of a separate method, which not surprisingly will be called “load().” 

Therefore, to see how this whole new method will be properly defined, read the next section.

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