PHP
  Home arrow PHP arrow Page 4 - Building 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

Building Loader Apps in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2009-05-27


    Table of Contents:
  • Building Loader Apps in PHP
  • Start building loading programs with a require_once() function
  • Building a basic file 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


    Building Loader Apps in PHP - The loader class in action
    ( Page 4 of 4 )

     

    Definitely, a good epilogue for this first chapter of the series will be demonstrating how the file loading class that you saw in the previous section can be put to work. With that premise in mind, below I included a short code sample that shows how to include the two sample files created earlier by using the loaded class. Here it is:

    <?php

     

    try

    {

    // create instance of loader class

    $loader = new Loader();

    // 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: 20:25:36

    */

    }

    catch (Exception $e)

    {

    echo $e->getMessage();

    exit();

    }

    ?>

    Well, as you can see in the above example, the two basic files defined previously have been successfully included by the “Loader” class via its pertinent “load()” method. In this particular case, it’s been assumed that both the class and the files being loaded reside under the same directory on the web server, but naturally it’s possible to specify the full paths of these files, if they’re incidentally located on a different folder.

    And with this last example, I’m finishing this introduction to building loader applications with PHP 5. This first part is pretty simple to digest, at least for experienced developers, but this is only the beginning.

    In the interim, feel free to edit all of the code samples included in this tutorial, and try to create your own file loader class. The experience will be truly educational.

    Final thoughts

    Over this first episode of the series, I explained how to construct a couple of basic file loading systems. The first mechanism used a procedural approach, while the last one relied on a class to load a specified file.

    However, I’d like to point out one important thing with reference to the way that the loader class was built. As you’ll recall, its “load()” method was called in an object context (in other words, dynamically), in order to include a specific file. This means that an instance of this class needed to be created -- something which can be easily avoided.

    But how can we do this? Well, by simply calling the mentioned method statically, it’s possible to avoid the unnecessary instantiation of the loader class. But the full details of this process will be discussed in the next article, so now that you’ve been told, you simply can’t miss it!



     
     
    >>> 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