PHP
  Home arrow PHP arrow Auto Loading Classes in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Auto Loading Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2007-12-04


    Table of Contents:
  • Auto Loading Classes in PHP 5
  • Traditional Approach
  • Traditional Approach continued
  • Using the Magic Function
  • Comparing the two

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Auto Loading Classes in PHP 5
    ( Page 1 of 5 )

    Undoubtedly, the release of PHP 5 has had a remarkable impact on the way that object-oriented applications are developed nowadays. This highly-improved model has provided PHP programmers with features that were only present in mature object-based languages, like Java and C++, but now, fortunately for you and me, they are generously offered by this powerful server-side scripting language.

    Of course, if you’ve been using PHP 5 for a while to build your object-oriented applications, then it’s likely that you’re already familiar with creating classes, defining their corresponding methods and properties, working with exceptions and interfaces, and so forth.

    However, even when all of the features that I highlighted actually comprise the foundations of the so-called object-based paradigm, it’d be rather unfair not to mention other useful characteristics that come packaged with PHP 5, which can help facilitate the development of object-oriented projects.

    Destructors and object deferencing are good examples of certain characteristics available in PHP 5, which can be extremely helpful when working with objects that need to be called when they no longer exist in the context of a given web application, or when a certain number of these objects must be chained with each other through their corresponding APIs.

    Nevertheless, among the improvements introduced into the object model provided by PHP 5, there’s one in particular that can be considered a programmer's best friend when using objects, due to its remarkable functionality. Do you think that I’m being too verbose here? Well, maybe, but this won’t stop me from telling you loud and clear the name of the improvement in question. Yes! You guessed right! In this case, I’m talking about the useful “__autoload()” PHP 5 magic function, which can be really magical when it comes to automatically loading all the class files required by a determined PHP application.

    As you might know, the “__autoload()” function, when used in a clever way, can eliminate almost completely the need to use the “require()/require_once()” and “include()/include_once()” PHP native functions to load your nicely-crafted classes automatically during the execution of an object-oriented application. This certainly speaks for itself about the powerful capabilities offered through this function.

    Personally, when I started “auto loading” all of my PHP 5 classes with this magic function, I realized that it was one of those things one can’t live without. Hopefully after you go through this series of articles, you’ll feel the same way.

    Actually I’m getting ahead of myself, so now is the perfect time to move forward and start learning how to put the “__autoload()” magic function to work for you, and load your classes without having to include them manually into your PHP 5 object-oriented applications. It’s going to be an educational experience. Believe me!



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT