There’s an interesting challenge in writing a good book about programming. At a certain point, you’ll lose the newbies and alienate the technical. Below the line is a safe introductory book, above it is aimed at a smaller crowd. We had an opportunity review No Starch Press‘ Object-Oriented PHP, and found it fits nicely into the gap.
When PHP moved from version 4 to version 5, it introduced several new technologies to PHP programmers, chiefly SimpleXML, improved MySQL handling, SQLite, exception handling, and most importantly, a completely new object-oriented model. Making the switch to PHP5 is easy for most, as your old style will likely still work, but becoming proficient in using those new features evens the playing field and places many veteran PHP programmers back in learning mode.
Enter “Object-Oriented PHP” (No Starch Press, 2006). The subtitle of the book is Concepts, Techniques, and Code, which is fitting, because the structure of the book is such that it discusses a problem, shows ways to overcome them, and then gives you the code.
The book starts by discussing what objects are, why one might use them, and then examines general PHP object syntax. Many PHP 4 programmers have written volumes of procedural code and have never written a class in their life. The books seeks to dispell the myth that classes are too complex and for large IT shops only. I’ve personally found that some code is easier with object-oriented architecture and some code is easier and faster with regular procedural code. However, OOP is certainly handy when you need reusable and portable objects.
For example, a hypothetical function in your application might be fewer characters than the OOP alternative, but certainly writing code to iterate a directory is much longer, and when you use the code in several pages, it grows exponentially. Several examples of such behavior are explained in clear, easy to understand steps by the book.
Object-Oriented PHP covers several topics. Although the layout is logical and reads well, the content of the chapters is inconsistent. For example, the first four chapters are very broad – they covers basics and fundamentals of OOP. However, in the middle are chapters entitled The ThumbnailImage Class and Building the PageNavigator Class, of which are very specialized, very specific codes that only have meaning or value to some programmers. As a result, they are more fitting for O’Reilly’s “Cookbook” series than a book aimed at teaching you the basics of a programming concept. However, chapters such as Chapter 120 “Improvement Through Inheritance” and Chapter 11, “Advanced Objected Oriented Programming Concepts” cover, in detail, aspects of OOP that aren’t immediately obvious even to those who use basic classes and elementary OOP concepts.
Another important concept that those seeking better understanding of PHP OOP will appreciate is chapter 13, which details “Magic Methods.” This chapter discusses a lot of the “meat” of PHP objects, and includes several advanced concepts.
Object-Oriented PHP covers several subjects in detail, including touching on PDO or “PHP Data Objects,” new to PHP 5.1, which is so bleeding edge that even several months after press time, it’s rarely found on hosted servers. Learning concepts such as XML manipulation, discussed in chapter 12, SQLite, discussed in chapter 15, and PDO in the final chapter would prepare any level PHP programmer for inevitable changes and new capabilities that have been or will be introduced to PHP, and certainly many of these features will become more prevelent with PHP6.
Overall, Object-Oriented PHP is a good book that can teach even experienced PHP programmers how to add reusable objects to their code. The included code samples will certainly be useful, provided the scenarios outlined suit you. I would recommend this book to those migrating a PHP4 skillset to PHP5 and to those who are interested in a solid introduction and competance with PHP Object-orientation.
Easy to understand
Provides solid foundation for PHP OOP
Discusses modern concepts such as SimpleXML and PDO
Chapters vary between concepts and code with little warning
Included code is specific and may not be of use to you