PHP
  Home arrow PHP arrow Using the spl_autoload() Functions to Build Loader Apps in PHP
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

Using the spl_autoload() Functions to Build Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 0
    2009-07-01


    Table of Contents:
  • Using the spl_autoload() Functions to Build Loader Apps in PHP
  • Review: the autoload magic function
  • Using the spl autoload extensions and spl autoload functions
  • Introducing the spl autoload register function

  • 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


    Using the spl_autoload() Functions to Build Loader Apps in PHP
    ( Page 1 of 4 )

    Welcome to the seventh installment of an eight-part series on building loader applications in PHP. In this part, you will learn how to use the “spl_autoload(),” “spl_register()” and “spl_register()” functions to build a small file loader class. This class will be able to perform recursive searches through the file system to find a targeted resource.

    As the passionate PHP developer that you probably are, you know that building file loading scripts is mostly a process that relies on the set of “include()/include_once()” and “require()/require_once()” functions, which you’ve surely used hundreds of times before.

    Nevertheless, it’s feasible to create more efficient and elegant loading scripts by merging the functionality provided by the mentioned functions with that given by the Standard PHP Library (SPL). In truth, it is quite simple to develop short programs that include a specified resource or class using a recursive search through the file system. This process was discussed in depth in previous installments of this series.

    But speaking more specifically, in the last tutorial I left off by explaining how to build a small file loading script with the handy “__autoload()” function, which is called by the PHP engine when it finds a reference to a class that hasn’t been included previously.

    By giving a customized implementation to the “__autoload()” function, it’s possible to include classes in a transparent way, without having to explicitly call any PHP includes. However, as I mentioned before, the Standard PHP library comes bundled with some helpful functions, such as “spl_autoload(),” “spl_register_extension()” and “spl_autoload_register()” that allow you to either use a default implementation of the “__autoload()” function, or create a custom one for it.

    This can be extremely useful when building reusable file loader programs. Thus, over this seventh episode of this series, I’m going to discuss how to use the aforementioned SPL functions to develop a few modular class loader scripts.

    Now that you’re aware of the primary goal of this tutorial, it’s time to start learning how to use the Standard PHP library for including classes in a true effective manner. Let’s get going!



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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