To Louise. Still the whole point.
When I first conceived of this book, object-oriented design in PHP was an esoteric topic. The intervening years have not only seen the inexorable rise of PHP as an object-oriented language but also the march of the framework. Frameworks are incredibly useful, of course. They manage the guts and the glue of many (perhaps, these days, most) web applications. What’s more, they often exemplify precisely the principles of design that this book explores.
There is, though, a danger for developers here, as there is in all useful APIs. This is the fear that one might find oneself relegated to userland, forced to wait for remote gurus to fix bugs or add features at their whim. It’s a short step from this standpoint to a kind of exile in which one is left regarding the innards of a framework as advanced magic and one’s own work as not much more than a minor adornment stuck up on top of a mighty unknowable infrastructure.
Although I’m an inveterate reinventor of wheels, the thrust of my argument is not that we should all throw away our frameworks and build MVC applications from scratch (at least not always). It is rather that, as developers, we should understand the problems that frameworks solve and the strategies they use to solve them. We should be able to evaluate frameworks not only functionally but in terms of the design decisions their creators have made and to judge the quality of their implementations. And yes, when the conditions are right, we should go ahead and build our own spare and focused applications and, over time, compile our own libraries of reusable code.
I hope this book goes some way toward helping PHP developers apply design-oriented insights to their platforms and libraries and provides some of the conceptual tools needed when it’s time to go it alone.
As always, I have benefited from the support of many people while working on this edition. But as always, I must also look back to the book’s origins. I tried out some of this book’s underlying concepts in a talk in Brighton, back when we were all first marveling at the shiny possibilities of PHP 5. Thanks to Andy Budd, who hosted the talk, and to the vibrant Brighton developer community. Thanks also to Jessey White-Cinis, who was at that meeting and who put me in touch with Martin Streicher at Apress.
Once again, this time around, the Apress team has provided enormous support, feedback, and encouragement. I am lucky to have benefited from such professionalism.
I’m very lucky to have had my friend and colleague, Paul Tregoing, working on this edition as Technical Reviewer. The fact that PHP itself was under active development throughout the writing of this book demanded extra vigilance. Code examples that were perfectly valid in early drafts were rendered incorrect by the language’s fast evolution. Once again, this edition has greatly benefited from Paul’s knowledge, insight, and attention to detail—many thanks Paul!
Thanks and love to my wife, Louise. The production of this book has coincided with three pandemic lockdowns, so thanks are also due to our children, Holly and Jake, for many much-needed distractions—often provided during Zoom meetings conducted in my office space (the corner of the kitchen table).
Thanks to Steven Metsker for his kind permission to reimplement in PHP a simplified version of the parser API he presented in his book, Building Parsers with Java (Addison-Wesley Professional, 2001).
I write to music, and, in previous editions of this book, I remembered the great DJ, John Peel, champion of the underground and the eclectic. The soundtrack for this edition was largely provided by BBC Radio 3’s contemporary music show, Late Junction, played on a loop. Thanks to them for keeping things weird.
has worked as a web programmer, consultant, and writer for over two decades. He is the author of SAMS Teach Yourself PHP in 24 Hours (three editions) and is a contributor to DHTML Unleashed. He has written articles for Linux Magazine, Zend, IBM DeveloperWorks, and php|architect magazine, among others. Matt was a senior developer/tech lead at Yahoo! and API tech lead at LoveCrafts. Matt works as a consultant advising companies on their architectures and system management and also develops systems primarily with PHP and Java. Matt also writes fiction.
He now works as a freelance engineer for various clients, small and large, building multitiered web apps using PHP, JavaScript, and many other technologies. Paul is a voracious consumer of science fiction and fantasy and harbors not-so-secret ambitions to try his hand at writing in the near future. He lives in Cambridge, United Kingdom, with his wife and children.
3.141.244.201