Validating user input in php

As usual with all my articles, feel free to modify the signature of all the classes that I showed here so you can acquire a better understanding of this pattern. Final thoughts Unfortunately, we’ve come to the end of this series.

However, I hope that after reading these two articles, you’ll have a better idea not only of how the strategy pattern works, but how it can be used in real situations.

Although the example that I just described may seem rather basic, it shows in a nutshell the logic that drives the strategy pattern: on one hand there’s a class that sets the context as to where a predefined group of strategies will be applied, while on the other hand there’s one or more classes that implement these strategies.

However, now that you hopefully digested the contents of the first article of the series, let me tell you what you’ll learn in this final tutorial.

validating user input in php-74validating user input in php-90

As I promised before, here are all the classes that I built over the course of this tutorial to apply the strategy pattern with PHP 5: That’s it.

Finally, the other two cases demonstrate how to use the same selector to validate numeric data and an email address.

All right, I believe that all these examples should give you an approximate idea of how the strategy pattern can be used in a real-world situation.

Having said that, the corresponding examples look like this: As you can see, the prior examples illustrate in a step-by-step format how the strategy design pattern can be used in a real situation, in this particular case, aimed at validating a wide variety of data types.

As you saw, the first two examples use the validation strategy selector to verify alphabetic and alphanumeric values in turn, and also display the respective results.

Leave a Reply