C H A P T E R 21
■ ■ ■
Objects, Patterns, Practice
From object basics through design pattern principles, and on to tools and techniques, this book has has
focused on a single objective: the successful PHP project.
In this chapter, I recap some of the topics I have covered and points made throughout the book:
- PHP and objects: How PHP continues to increase its support for object-oriented
programming, and how to leverage these features. - Objects and design: Summarizing some OO design principles.
- Patterns: What makes them cool.
- Pattern principles: A recap of the guiding object-oriented principles that underlie
many patterns. - The tools for the job: Revisiting the tools I have described, and checking out a few I
haven’t.
Objects
As you saw in Chapter 2, for a long time, objects were something of an afterthought in the PHP world.
Support was rudimentary to say the least in PHP 3, with objects barely more than associative arrays in
fancy dress. Although things improved radically for the object enthusiast with PHP 4, there were still
significant problems. Not the least of these was that by default, objects were assigned and passed by
reference.
The introduction of PHP 5 finally dragged objects center stage. You can still program in PHP without
ever declaring a class, of course, but there can be no doubt that the language is optimized for object-
oriented design.
In Chapters 3, 4, and 5, I looked at PHP’s object-oriented support in detail. Here are some of the new
features PHP has introduced since version 5: reflection, exceptions, private and protected methods and
properties, the toString() method, the static modifier, abstract classes and methods, final methods
and properties, interfaces, iterators, interceptor methods, type hinting, the const modifier, passing by
reference, clone(), the __construct() method, late static binding, and namespaces. The extensive
length of this incomplete list reveals the degree to which the future of PHP is bound up with object-
oriented programming.
I would still like to see a few features that are not yet planned, such as hinting for primitive types. I
would also like to see support for return type hinting—in which a method declaration can include the
return type the method must yield. The engine would then enforce this commitment, both for the
current and overriding methods (at the time of writing, this feature is slated for a future release).
These are quibbles, though. The Zend Engine 2 and PHP 5 have made object-oriented design central
to the PHP project, opening up the language to a new set of developers and opening up new possibilities
for existing devotees.
In Chapter 6, I looked at the benefits that objects can bring to the design of your projects. Since
objects and design are one of the central themes of this book, it is worth recapping some conclusions
in detail.