Home arrow PHP arrow The Autoload Magic Function in PHP 5

The Autoload Magic Function in PHP 5

Among the improvements and new features that were introduced to PHP 5, there’s a set of special functions, popularly known as magic functions. These allow you to perform all sorts of smart tasks, ranging from overloading properties and methods in classes, to using destructors and triggering automatically predefined processes when serializing and unserializing objects. This is the conclusion to a seven-part series that shows you how to use the magic functions in PHP 5.

  1. The Autoload Magic Function in PHP 5
  2. Review: the destruct method
  3. Loading classes automatically with the autoload magic function
  4. Loading classes in the background with the autoload function
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
June 22, 2009

print this article



So, if you’re a PHP developer who wants to learn how to put these magic functions to work for you in a truly effortless way, or wishes to fill some gaps in your knowledge regarding their correct implementation and usage, then this group of tutorials might be the guide that you’re looking for.

And now that you know what to expect from this series of articles, it’s to review the topics that were discussed in the last one. In that particular tutorial I discussed the implementation of a destructor method within a simple class, via the pertinent “__destruct()” function.

In that particular situation, this function was provided with the capability to save an instance of the originating class to a session variable before being destroyed by the PHP interpreter. In doing so, I hopefully demonstrated how to create basic persistent objects by using only a simple destructor. Not too bad at all, right?

However, PHP 5 offers yet another magic method that can be extremely useful for loading classes automatically, without having to use explicitly any “include()/include_once()” or “require()/require_once()” function. As the article’s title suggests, I’m talking specifically about the “__autoload()” function, which deserves a deeper analysis.

Therefore, this last chapter of the series will be focused exclusively on exploring the potential of this function for including classes in a transparent way. So, jump ahead and start learning more about it!

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