PHP
  Home arrow PHP arrow Page 4 - Using Static Methods 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 Static Methods to Build Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2009-06-03


    Table of Contents:
  • Using Static Methods to Build Loader Apps in PHP
  • Review: a basic file loading system with PHP 5
  • A static file loading method
  • Loading files using a static class method

  • 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 Static Methods to Build Loader Apps in PHP - Loading files using a static class method
    ( Page 4 of 4 )

     

    To finish this second part of the series, I'm going to develop a short example to demonstrate how to include the pair of sample files shown previously by means of the “Loader()” class. In this case, of course, the “load()” method will be called statically.

    Now that I have explained that, please pay close attention to the example, which looks like this:

    <?php

    try

    {

    // call 'load()' method statically and load specified files

    Loader::load('sample_file1.php');

    Loader::load('sample_file2.php');

     

    /* displays the following

     This file has been loaded with the Loader class.

    This file has been loaded at the following time 2:45:18

     */

    }

    catch (Exception $e)

    {

    echo $e->getMessage();

    exit();

    }

    ?>

    As shown above, it’s perfectly possible to load as many files as required via the “Loader()” class, without needing to create an instance of it. Of course, this is a great improvement in the way that certain dependencies are included into a given PHP application, even when it’s necessary to make one static call per requested file.

    But I’m only scratching the surface when it comes to building loading programs with PHP 5, so for the moment feel free to tweak all of the the code samples developed in this article and try to create a better loader class. The exercise will be really worthwhile.

    Final thoughts

    In this second part of the series, I explained (through various code samples) how to enhance the file loader class created in the first chapter simply by declaring its “load()” method static, and obviously by calling it statically as well, when including a specific file.

    This is definitely a great breakthrough toward the development of an efficient file loading application, but there is still plenty of room for further enhancements. Therefore, in the upcoming article I’m going to extend the functionality of the loader class by providing it with the capacity for including files recursively.

    Want to learn the full details of this process? Then don’t miss the next chapter!



     
     
    >>> 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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek