HomePHP Enhancing a URL Handling Helper Class in PHP 5
Enhancing a URL Handling Helper Class in PHP 5
Are you a PHP developer wishing to find an approachable guide that walks you through building different kinds of helper classes in PHP 5? Then look no further, because this group of articles may be the material that you really need.
Welcome to the fourth part of a series on building helpers in PHP 5. Comprised of eight tutorials, this series shows how to create some of the most common types of helper classes found in many popular PHP frameworks, and it complements the corresponding theoretical concepts with numerous code samples.
Having already outlined the goal of this set of articles, now it's time to review the topics that were treated in the last one, so you can see how they'll link with the subject of this fourth tutorial. In that specific article I went through the development of a basic URL-handling helper class, whose methods behaved in most cases as simple wrappers for some of the values available in the native $_SERVER superblobal PHP array.
While it's fair to say that the structure and logic implemented by this helper class was rather rudimentary, it's worth stressing that it demonstrated how to build a URL helper class in PHP 5 in a straightforward fashion.
Of course, the class in question is susceptible to being enhanced, and that's precisely what I'm going to do in the next few lines. You might be wondering how. Well, as you'll possibly recall, all of the methods of the class were called initially inside the object context, that is dynamically, which may lead to the creation of an unnecessary instance of the helper class.
So, to solve this issue quickly, in this chapter of the series I'm going to redefine the signature of the previous URL helper class by declaring all of its methods static. Thus the question now is: are you ready to learn the full details of how this will be accomplished? Then don't waste more time; start reading right now!