Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 2 ■ STATIC VARIABLES, MEMBERS, AND METHODS^19

To access static methods, you use the paamayim nekudotayim operator (::), which is also
called the scope resolution operator. The left side of this operator takes a class name or one of
the magic scopes: self, parent, or in PHP 6, static. The right side takes a static method, vari-
able, or constant. The self magic scope, when used from within a class, refers to the class itself.
The parent magic scope refers specifically to the parent class and can be especially useful for
accessing methods in the base class that may have been overridden.
Static classes can have consequences to certain types of testing. The IoC design principle
is limited when static classes are used in PHP. This is because static usage can lead to binding
classes together by name, and that makes isolated testing of components more difficult. In the
end, however, most PHP applications do not utilize IoC principles, and static usage is typically
preferred.

McArthur_819-9C02.fm Page 19 Friday, February 1, 2008 10:23 AM

Free download pdf