HomePHP Building Dynamic Web Pages with Polymorphism in PHP 5
Building Dynamic Web Pages with Polymorphism in PHP 5
If you’re starting to delve deeper into object-oriented programming with PHP, and also want to know how to include polymorphic objects into your own scripts, this might be the right opportunity to learn more about this interesting topic. Welcome to the second part of the series that began with “Using polymorphism with objects in PHP 5.” In three articles, this series provides you with a comprehensive guide on how to take advantage of polymorphism to build more efficient object-based PHP applications.
If you already read the first article of the series, then it's quite probable that the concept of working with polymorphic objects is now very familiar to you. However, in case this subject doesn't ring any bells, let me offer a brief introduction. This will give you a more solid background for tackling the group of topics that I plan to cover in this article.
In short, Polymorphism is a feature exposed by certain objects that belong to the same family, which eventually can behave differently, even when they're using identical methods. Or more clearly, an object can be considered polymorphic when it's capable of performing different actions by utilizing the same method.
As you can see, this feature can be really useful in certain situations where using polymorphic objects can improve noticeably the way that a specific application is structured, aside from avoiding the inclusion into the source code of redundant checking blocks, such as the popular "if" and "switch/case" combinations.
The previous theory was clearly demonstrated in the preceding article, where I showed how to take advantage of polymorphism by building a simple yet expansible database abstraction layer for working with MySQL and SQLite. Obviously, the aforementioned layer used polymorphic objects for accessing both database systems, but this concept can be easily extended to other applications, which makes it even more interesting.
Therefore, bearing in mind that the implementation of polymorphic objects in PHP 5 can be indeed as useful to you as it is to me, in this second part of the series, I'm going to show you how to use polymorphism to build dynamic web pages.
The experience not only will be interesting, but also educational, so let's not waste more time in preliminaries.