Home arrow PHP arrow Using Static Methods to Build Loader Apps in PHP

Using Static Methods to Build Loader Apps in PHP

If you’re a PHP developer who has already worked with popular third-party frameworks like Kohana and CodeIgniter, or even better, have created one all by yourself, then you're familiar with building file loading applications. The process can be tackled pretty easily, either by using a procedural approach or the object-oriented paradigm. In this eight-part series, we take a close look at building file-loading applications. This second part of the series will focus on static methods.

TABLE OF CONTENTS:
  1. Using Static Methods to Build Loader Apps in PHP
  2. Review: a basic file loading system with PHP 5
  3. A static file loading method
  4. Loading files using a static class method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
June 03, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As its name suggests, a file loading program (or a resource loading program, to express the concept more accurately), is simply a PHP module that takes care of including, usually via its set of “include()/require() native functions, files that are required by an application to make it work as expected.

In many cases, loading files within a program can be seen simply as a one-to-one relationship, where one “include()/include_once() or “require()/require_once()” function is used explicitly with each required file. Although this method can be quite effective when developing small-scale applications, it can lead to many maintenance headaches when building larger ones.

Fortunately, it’s possible to create more sophisticated and elegant file loaders with minor hassles, by combining classic PHP includes along with the magic “__autoload()” function and some of the functions and classes supplied by the Standard PHP Library (SPL) available in PHP 5.

The goal of this series of articles is to demonstrate, in a step-by-step fashion, how to build several file loading programs. These range from using a “require_once()” function per requested file, to developing loader classes capable of including a specified file by using a recursive search through the file system on a web server.

Actually, I’m getting ahead of myself, since it’s time to summarize the topics that were covered in the first part of this series. In that article, I explained how to create a rudimentary file loader class, which via a dynamic “load()” method, had the ability to include a specific file into a given application.

It’s worthwhile to mention, however, that it was necessary to create an instance of the aforementioned class to load a determined file. This is a process that can be completely avoided in terms of good coding habits. But how can this be achieved? Well, it’s feasible to statically call the class’s load()” method,  preventing its unwanted instantiation.

So, in the next few lines I’m going to illustrate how to do that, by way of a decent variety of code samples that you’ll grasp very quickly.

Are you ready to tackle this second installment of the series? Then let’s move forward now!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: