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

 
Developer Updates  
Free Website Content 
eWeek
 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: 3 stars3 stars3 stars3 stars3 stars / 10
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Create a Highly Available Database Solution. Advantage Database Server can provide the availability to keep your data safe and ready for your application and users.

    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


       · Ever wanted to build PHP 5 scripts that load automatically your source classes...
       · Yeah I Used This For A While. But Notice That If You Have Some Variables Or...
       · Thank you for commenting on my PHP article. Yes, what you mention is a cons in using...
       · You did not say (or I missed it) what happens if you use both methodologies. If a...
       · Thank you for commenting on my PHP article. Concerning your question, simply I...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway