HomePHP Building a More Capable Validation Helper Class
Building a More Capable Validation Helper Class
In this sixth part of an eight-part series on helper classes, I finish developing the validation helper class created in the previous part. We'll add even more useful validation methods to expand its functionality.
Quite often, helper classes are overlooked by developers taking their first steps in PHP-based web development. They are used to encapsulate all of the functionality required to perform certain tasks in full-featured, large-scale libraries, which sometimes contributes to breaking down the intrinsic modularity imposed by the object-oriented paradigm.
However, experienced programmers know that helper classes play an important role when it comes to speeding up the development of web applications, in typical situations where it’s necessary to dynamically generate different portions of a URL, validate incoming data or apply different formatting filters to a group of database records.
Given the relevance that helper classes have in the life of conscientous PHP developers, they deserve a closer analysis that must be complemented with a decent variety of examples that show how to build them and how to use them in concrete cases.
So, if you’re interested in learning the basic concepts that surround the creation of helpers, then this series of articles might provide the material for which you’re looking.
Logically, if you had the chance to read all of the tutorials that precede this one, then it’s quite probable that you now have a more solid background in building several helper classes with PHP 5. In those articles I offered numerous examples that hopefully demonstrated how to accomplish this process in a relatively easy way.
In the last chapter I started developing a simple helper class whose main task was to validate different types of data, such as integer and float numbers, and alphabetic and alphanumeric values, by using the capabilities provided by the PHP filters extension.
Admittedly, in its current state, this helper class has limited functionality. It would be really useful to add more methods to it to validate other things, like email and IP addresses, to mention just two examples. Thus, in the next few lines I’m going to extend the abilities of this helper class so it can be used to perform the validation processes mentioned above.
Now, it’s time to get rid of the preliminaries and keep digging deeper into the huge terrain of PHP helper classes. Let’s get going!