Static Classes

In Chapter 9, you used a static data member to allow only one instance of the MySQL database class. Whenever an attempt was made to create an instance of this class, you were able to test the value of the $instances variable to ensure that no other instances existed. This test works because a variable declared as static is available to all instances of a class (or in this case, would-be instances).

Static Math Classes

The ability to create classes that are entirely static allows us to encapsulate a set of related unchanging data members and methods. Mathematics is an ideal candidate for this kind of class because constants, such as pi and the way of calculating the absolute value of a number, do not change. Listing 11-3 shows ...

Get Object-Oriented PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.