on September 12, 2009
I purchased Peter Lavin's OBJECT ORIENTED PHP and began reading it while I sat at my keyboard. After a few chapters I quickly realized that PHP's OO approach is similar to Java's, but easier because PHP is loosely typed. Although I followed the book for a couple of chapters, creating classes that form the basis of an online Photo Gallery, I quickly got side-tracked into creating the kinds of classes I might actually end up using in future projects.
Within a day I'd created a handful of classes for the common functions required in any interactive Web application: an SQL QueryBuilder class, a UserManager class, and a LoginManager class. This is the power and primary benefit of an OO approach. The code is modular and reusable. Data hiding through encapsulation and a combination of private and public methods (functions in PHP), make the creation and using of classes an investment in the scalability and maintainability of current projects, but also in future productivity.
Lavin's book is very good but has some structural problems. The first three chapters do not engage the neophyte Object Oriented developer, but instead focus on the intricacies of the Object Oriented framework as deployed in PHP; almost like a 3-chapter changelog. The first hint that Lavin is actually aiming at an audience unfamiliar with Object Oriented concepts is chapter 4. Despite that, once the book gets going the approach is straightforward and easy to understand. The project that forms the hands-on learning component is quite useful and illustrates both Object Oriented concepts and the full iterative nature of Object Oriented development quite nicely. Within one chapter you end up with a usable class that traverses and displays all pictures in a given directory, and the rest of the book scales up the functionality of that class by extending it and adding new classes, methods, etc.
One caveat. This book is not for inexperienced developers. Unless you've got a solid grounding in XHTML, CSS, traditional procedural PHP and MySQL, it will be a difficult read. On the other hand, if you're already familiar with an Object Oriented language like Java, learning object orientation in PHP is simply a matter of picking up the correct syntax. For those interested in exploring PHP development frameworks like CakePHP of Symfony, Lavin's book will provide a grounding in Object Oriented development that will pave the way.