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:
// call 'load()' method statically and load specified files
/* 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)
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.
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!
blog comments powered by Disqus