Matt Zandstra

PHP 8 Objects, Patterns, and Practice

Mastering OO Enhancements, Design Patterns, and Essential Development Tools

6th ed.
Matt Zandstra
Brighton, UK
ISBN 978-1-4842-6790-5e-ISBN 978-1-4842-6791-2
© Matt Zandstra 2021
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To Louise. Still the whole point.

Introduction

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.

Acknowledgments

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.

Table of Contents
Part I: Objects1
Part II: Patterns239
Part III: Practice557
Books 781
Sites 782
Index 817
About the Author
Matt Zandstra

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.

 
About the Technical Reviewer
Paul Tregoing
../images/314621_6_En_BookFrontmatter_Figb_HTML.jpg
has worked in ops and development in a variety of environments for nearly 20 years. He worked at Yahoo! for 5 years as a senior developer on the frontpage team; there he generated his first PHP using Perl. Other employers include Bloomberg, Schlumberger, and the British Antarctic Survey, where he became intimate with thousands of penguins.

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.

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.244.201