HomePHP Introducing Static Members and Methods in PHP 5
Introducing Static Members and Methods in PHP 5
Static properties and methods can be quite useful in a range of situations, not merely for constructing a Singleton class. This article, the first in a two-part series, introduces the basic concepts of static properties and methods, using plenty of hands-on examples.
Since its official release, PHP 5 has gained wide acceptance among PHP developers around the world, particularly in those cases where the natural evolution of web programming requires working with a robust object model. Not surprisingly, modern PHP 5-based applications now make intensive use of the broad range of features included with the last incarnation of the language, which in general leads to building better-crafted application layers.
If you’ve been using the highly improved object model that comes with PHP 5 for a while, then you’ve possibly used static members and methods as an important part of your classes. This feature is very convenient to implement in those situations where a specific class member or method needs to be modified from outside the object context.
Although at first glance, static properties and methods seem to be a minor topic to consider, the truth is that they can be quite useful in specific cases. Of course, one of the most common occasions where both static members and methods can be properly exploited is when constructing a typical Singleton class, but there are other cases too. Therefore, if you’ve been using pattern-based programming for building your PHP programs, you’ll know what I’m talking about.
Considering the fairly huge range of applications where static properties and methods can be successfully used, in this two-part series, I’ll take an in-depth look at them. I will be introducing their basic concepts, as well as demonstrating their usage by copious hands-on examples.
Hopefully, by the end of this series you should be equipped with a decent knowledge of how to include static members and methods within your PHP applications with minor difficulties.
Want to know how the first chapter of this story begins? Click on the link below and keep reading.