On my flight to the DC PHP Conference in Washington D.C. I had a chance to read a copy of Pro PHP: Patterns, Frameworks, Testing and More written by Kevin McArthur. I’ve never written a book, I clearly don’t have a first hand appreciation for the amount of work that undoubtedly goes on under the hood. Given that I will try to be as constructive with this review as possible.
First I think it’s important to cover the valuable aspects of the book as that will really drive your decision whether the book is worth a read. If you are new to object oriented programming and basic design patterns you will get a fairly good introduction of how to do both in PHP. Part 1, OOP and Patterns, covers things like abstract classes, interfaces, exception handling and a couple of design patterns. The list of valuable design patterns in this section of the books is far from exhaustive so I’d strongly encourage you to supplement what is in this book with a book dedicated to patterns (as well as anti-patterns). One of the best chapters in Part 1 is on Exceptions and I was specifically glad to see Kevin articulate when *not* to use exceptions as it is my experience they are often over used and used improperly. Sort of the square peg in a round hole in Part 1 was a section on what’s new in PHP6 which, in my opinion, is a bit premature and it should be noted that some of the features listed in PHP6, specifically the support of namespaces, may actually show up sooner than advertised (PHP rumor mill suggests namespaces may make it into version 5.3 which is further rumored to be out around the first of next year). Because this Part of the book is five chapters yet only 52 pages don’t expect a ton of detail on object oriented programming and design patterns, though, you will get a decent introduction.
The order of where things showed up in this book was a problem for me. Part 2 is on Testing and Documentation while Part 4 is dedicated to the Model-View-Controller (MVC) design pattern. At the very least Part 4 should follow Part 1′s discussion on design patterns and, better yet, all of Part 4 should have been merged with Part 1. That said, I was pretty happy with the talk on testing and documentation. Kevin does a good job talking through the use of PHPDoc and PHPUnit both of which should be in any PHP developer’s toolbox. Part 2 also has a good discussion on Reflection which, back to the organization of the book, could have probably been a better fit in the discussion of object oriented programming, though, he did have a lengthy section on parsing reflection-based documentation data. Kevin did a great job covering the topic of reflection but I was a bit surprised to see no mention of how using reflection can negatively impact performance of your PHP application. Which brings me to my biggest criticism of the book.
With a title like “Pro PHP” I’d expect a few chapters dedicated to performance, scalability and security. While I’m a huge fan of object oriented programming and know a bit about the value software frameworks they often work counter to scalability and performance. This book had no mention of opcode caching, no discussion on application caching, database caching and the use of shared memory (RAM). Maybe that is intended to be another book in and of itself? Nonetheless, having a chapter or two on security is something that is needed if we want to fix the internet. Indeed application security is the subject of many books so I wouldn’t expect a book on “Pro PHP” to be exhaustive but today’s hackers are trending toward looking for applications holes instead of networking holes because a) they are usually easier to exploit and b) there are a lot of applications looking to be exploited. XSS, CSRF, SQL Injection, etc are all things developers need to be conscious of when writing code (regardless of language) and ignoring security is this book seems to be a bit irresponsible. I know, I know…tough words and, again, you can only effectively cover so much in one book but security definitely should have made the cut.
Part 3 covered the The Standard PHP Library (SPL). This quite possibly was one of the strongest points of the book. SPL’s top features are iterators of all sorts, file and directory handling and advanced array handling. Kevin covers all this and more in great detail. I was surprised to learn how many different types of iterators supported by SPL and I would recommend this entire book based on how well SPL was covered.
Part 4 of Pro PHP does a good job covering the most essential parts of the Zend Framework particularly they MVC implementation, logging and access control. In the world of PHP frameworks Zend is becoming more of a household name but I’d simply add that there are a lot of PHP frameworks out there. While the author is clearly a fan of the Zend Framework and does a good job showcasing some of it’s strengths please leave knowing they aren’t they only game in town.
AJAX/JSON and Web Services via SOAP are covered by Part 5 of the book. AJAX and JSON in PHP can also be it’s own book given all the AJAX libraries out there. Kevin does a great job giving a quick overview of AJAX and talks a bit on how to use it with the Zend Framework. This will only wet your appetite on the subject but I felt it was a pretty good start. The following chapters focused exclusively on Web Services and SOAP. PHP5 has solid support for SOAP minus some interoperability issues and Kevin covers this well. As a shameless plug I’d also point anybody doing SOAP-based web services in PHP to check out the PHP SOAP Toolket (PST) which works around some of the interop issues. Additionally I’d also point you to this utility that gives you all the features of PST without having to install a thing. I digress…back to the book. One thing I feel that PHP is really good at is support for REST-based services which is largely ignored by this book. I think in a book like this you can only effectively cover one of either SOAP and REST, however, I would have liked to see REST at least mentioned and a quick comparison of when you might use one versus the other.
This book has also been reviewed by a number of other talented people so please feel free to factor their opinions in with mine to see if this is a book for you. I honestly do feel this book has a place on your bookshelf particularly for those just diving in more advanced PHP development.