PHP
  Home arrow PHP arrow Page 4 - Using Directory Iterators 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? 
Google.com  
PHP

Using Directory Iterators to Build Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-07-02


    Table of Contents:
  • Using Directory Iterators to Build Loader Apps in PHP
  • Review: the previous class loader program
  • Improving the definition of the Autoloader class using directory iterators
  • Putting the Autoloader class into action

  • 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 Directory Iterators to Build Loader Apps in PHP - Putting the Autoloader class into action
    ( Page 4 of 4 )

     

    As you may have noticed when I showed the improved signature of the "Autoloader" class, it used a constant called BASEPATH to start looking for a specified class. But in this particular case, this constant will be defined outside the class, instead of storing its value as a property.

    Naturally, you can change this condition and take the approach that best fits your needs and requirements. So, having clarified that point, let me show you a simple script that demonstrates how to  dynamically include the previous "User" class.

    The code required to perform this task is as simple as this:

    // define base path to search for specified class

    define('BASEPATH', $_SERVER['DOCUMENT_ROOT'] . '/loader_classes/');

    // create instance of User class (it's autoloaded by the Autoloader class)

    $user = new User();

    // display user data

    echo $user; 

    In reality, apart from creating an instance of the sample "User" class and displaying some data on it, the above script only defines the corresponding BASEPATH constant and nothing else, since the inclusion of the class is handled behind scenes via the autoloading application.

    Even though this concrete example only shows how to include a trivial class, it still illustrates in a nutshell how to build efficient loader programs in PHP 5 that take advantage of the functionality provided by the Standard PHP Library.

    From this point onward, feel free to edit all of the code samples developed in this tutorial to help you get started developing your own file loading programs. 

    Final thoughts  

    It's hard to believe, but we've come to the end of this series. I hope the experience has been educational, since through all the tutorials you learned how to build different kinds of file loader programs with PHP 5.

    Ranging from explicitly using PHP includes to working with some of the functions and classes available in the Standard PHP Library, the variety of applications that load classes transparently is pretty huge. But, since the logic implemented by those programs is very similar, you shouldn't have major problems adding them to your toolbox.

    See you in the next PHP development tutorial!



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

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek