Home arrow PHP arrow Using the _autoload() Magic Function to Build Loader Appps in PHP

Using the _autoload() Magic Function to Build Loader Appps in PHP

Welcome to the sixth part of an eight-part series that shows you how to build file loader applications in PHP. In this part I will discuss how to build a helpful file loading application by taking advantage of the nifty __autoload() magic function.

  1. Using the _autoload() Magic Function to Build Loader Appps in PHP
  2. Review: building a file loader class the old way
  3. Loading files with the autoload PHP magic function
  4. Implementing an enhanced exception mechanism
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
June 24, 2009

print this article



There are a number of tasks that PHP developers must tackle on a regular basis when building well-structured web applications. One of these is creating scripts that load a certain number of resources and dependencies required for those applications to work as expected.

While developing these file loading scripts can be as simple as using PHP includes for each requested file, there are specific situations when its necessary to create more complex loader programs that incorporate some additional features, such as automatic inclusion of dependencies, and recursive search of them across a given file system path as well. 

Developing an application like the one described above with PHP 5 isnt as hard as it may seem at first glance, especially when taking advantage of the functionality provided by the Standard PHP Library (SPL) in conjunction with the __autoload() magic function. 

In the previous installments of this series I went through the process of creating a file loader class. This class was not only capable of seeking and including a targeted file by recursively traversing the directories and subdirectories of a supplied path, but it had the ability to perform this task without having to spawn any instances of the aforementioned class.  

How was this achieved? Well, by simply calling the class's main loader method statically and nothing else. It was that easy, really. 

But, as I mentioned a few lines before, its also feasible (and desirable) to construct file loading applications by combining certain built-in features of PHP 5, such as its __autoload() magic function, among others. Therefore, in this sixth chapter of the series Im going to explain how to build a brand new file loader mechanism that will rely on this PHP 5 function. 

Now, its time to leave all of the preliminaries behind us and start learning how to create a file loading system around the handy __autoload() function. Lets begin right away!

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