HomePHP Generating Outputs from MySQL with Static Members and Methods in PHP 5
Generating Outputs from MySQL with Static Members and Methods in PHP 5
Trying to expand beyond the boundaries of your existing background by learning how to code and use static methods and properties inside your PHP 5 classes? Then look no further. Welcome to the last part of the series “Using static members and methods in PHP 5.” Made up of two instructive chapters, this series introduces the foundations of using static members and defines static methods in PHP 5-driven development environments.
If you’re anything like me, then it’s quite probable that you’ve already included static members and methods in your PHP 5 classes, which means that you should consider yourself a fairly experienced developer.
On the other hand, for those who are completely new to the object model introduced with PHP 5, the subject in question is quite simple: essentially, static methods are those that are callable from outside the regular object context (using the :: scope resolution operator), and therefore can to be invoked without needing to use a specific class instance.
In addition, properties that have been declared static inside a class should be accessed from outside the object scope, via the “self” keyword, instead of using the $this pseudo variable. However, even though all these concepts may sound a bit intimidating, things are much simpler than you think, since declaring class methods and properties static is achieved by prefixing them with the “static” PHP keyword. That’s all.
Of course, as with most features of a specific programming language, using static members and methods needs to be taught by practical examples, which leads directly to the subject of this article. Since in the first tutorial you were provided with a couple of concrete cases where a class used a static property, as well as one static method (remember the definition of the Singleton class), in this tutorial you’ll see another example where these kinds of methods and members are properly utilized.
Specifically, I’ll show you how to use static methods to generate disparate outputs from MySQL database tables. If this topic sounds appealing to you, it’s time to get started. Let’s go!