It's pretty common when using PHP to develop dynamic, object-oriented applications. Every so often, though, you need to work with static data. This article will explain how to work with static data and static properties, and show you how this ability can be useful in real-world situations.
When you start learning some of the most important concepts for using the object-oriented paradigm with PHP, you quickly realize the remarkable benefits of building classes and objects, defining their methods and properties, and working with aggregation and composition as well.
Of course, things get interesting when you begin applying the pillars of object-based programming, such as inheritance and polymorphism. At that point you've already acquired a decent background in developing dynamic, object-oriented PHP applications. I purposely used the term "dynamic" because it implies the existence of one or more classes that perform different tasks and output "dynamic" results.
However, while defining a bunch of dynamic methods for a given class certainly is one of the most common process that a PHP developer has to tackle on a frequent basis, the truth is that the powerful object model offered by PHP 5 allows you to work with static data too, in a very approachable fashion. But, in the context of PHP programming…what does static data mean?
Well, in simple terms, when a method of a class is declared static, it can be called from outside the object context, just like a conventional PHP function, thus avoiding the direct instantiation of that particular class. Pretty useful, right?
Besides, there's more good news on the horizon, since PHP 5 does let you work with static properties, which means that when a class property is declared static, then it will be unique for the entire class, in this way being callable from outside the object context, and also shared by all the instances of that specific class.
Perhaps, if you reread the above sentences, you may find the concept of working with static data in PHP 5 rather hard to grasp, or even pointless, but the truth is that in real world situations, this feature can be extremely useful. Therefore, and assuming that the subject of this series has already caught your attention, in this group of tutorials I'll be taking a close look at creating and using static properties and methods with PHP 5, and also provide you with numerous hands-on examples so you can acquire a solid grounding in this important topic.
Are you ready to learn how to declare and use static data with PHP 5? Then don't you stay static; begin reading now!