HomePHP Working Out of the Object Context to Build Loader Apps in PHP
Working Out of the Object Context to Build Loader Apps in PHP
Welcome to the fifth part of an eight-part article series that teaches you how to build loader applications with PHP. In this installment of the series, I explain how to create a small, efficient file loader class, with a difference: no instance of it needs to be spawned to include a targeted file, thanks to the implementation of a static recursive loading method.
Building small programs with PHP that can load a specified file or resource is an easily-tackled process for many developers with only average experience in the language. However, things can get more complex when trying to add some useful characteristics to these programs, such as recursive file search capabilities and exception handling. This requires a more intimate knowledge of the object paradigm and mastering some features that are only present in PHP 5.
Not all is lost, though, if you're trying to build this kind of file loading application, since this group of articles will guide you through the entire development process in a truly friendly way, using a strong hands-on approach.
Of course, if you've been a patient reader who already went through all of the preceding articles of this series, then you probably have a solid background in how to create some handy file loading programs with PHP 5. In the aforementioned tutorials I discussed their construction, and once the basic concepts were properly covered, I proceeded to implement a few useful features, such as the capacity for including a specified file by means of recursive searches, using a starting file path.
The file loader class developed in the last chapter had a "load()" method that implemented this recursive ability in a truly straightforward fashion. Nevertheless, it's valid to stress here that it's necessary to create an instance of this class to include a determined file, except in those cases where its loading method is called statically.
However, to avoid an eventual (and unnecessary) instantiation of the loader class, it would be helpful to declare the mentioned "load()" method static. Thus, bearing in mind this important concept, in this fifth part of the series I'm going to enhance the signature of the "Loader" class created previously by turning its loading method into a static one.
Want to learn the full details of how this will be accomplished in a few simple steps? Then don't waste more time; start reading now!