PHP
  Home arrow PHP arrow Page 4 - Working Out of the Object Context 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

Working Out of the Object Context to Build Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-06-25


    Table of Contents:
  • Working Out of the Object Context to Build Loader Apps in PHP
  • Review: recursive file loading program
  • Improving the definition of the Loader class
  • The Loader class in 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


    Working Out of the Object Context to Build Loader Apps in PHP - The Loader class in action
    ( Page 4 of 4 )

     

    Certainly, the best way to demonstrate how the enhanced version of the "Loader" class works is through a concrete example. Therefore, bearing that concept in mind, below I included an easy-to-grasp code snippet, which uses the static "load()" method of the class to include the two sample PHP files that you saw at the beginning of the article. 

    Here's the example:

     

    // example of usage of the recursive loader class

    // prepare path to search for the specified file

    $path = $_SERVER['DOCUMENT_ROOT'] . '/path';

    // try to load the first specified file

    Loader::load('sample_file1.php', $path);

    // try to load the second specified file

    Loader::load('sample_file2.php', $path);

     

    /* displays the following

    This file has been loaded with the Loader class.

    This file has been loaded at the following time 22:18:21

    */

     

    That was pretty simple to code and read, wasn't it? As you can see, now the sample files have been successfully included by the above script, without having to spawn an unnecessary instance of the "Loader()" class. 

    In this particular case, I decided to feed the method with a fictional starting path to look for those files, but as homework for you, I suggest you try using different paths and changing their locations to see how the class behaves in each case. The experience will be pretty instructive, and also fun. 

    Final thoughts 

    That's all for the moment. In this fifth installment of the series I explained how to create a small -- yet efficient -- file loader class, but in this particular case, no instances of it need to be spawned to include a targeted file, thanks to the implementation of a static recursive loading method. 

    Also, as you may have noticed, the loader class developed so far doesn't use the "__autoload()" magic function included with PHP 5. So, it's time to take advantage of it, don't you think? Therefore, in the upcoming article I'm going to discuss how to build a file loading program  using this handy function. 

    As usual, here's my final suggestion: don't miss the next part!



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

       

    PHP ARTICLES

    - 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...
    - Mastering WHILE Loops for PHP and MySQL





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