Can a single book get web designers to start writing better, reusable PHP code? Peter Lavin makes a go of it in Object Oriented PHP, and it comes out pretty darn well.
The gist of the book is this: would you rather write code that does the same sort of stuff over and over and over and over and... so on and so forth, or would you rather write a piece of code you can plug into any of your pages or sites when you need to do a certain thing? The object-oriented way involves a little more time upfront, but it pays off time and time again. Because, let's face it, none of us enjoys coding the same boring stuff unless we're gluttons for punishment.
Some may say, "What?! What's this nonsense about OOP with PHP?" — and I will duly point them to the specs for PHP 5. That's when OOP techniques were truly made possible. I tell you, even I started reading Peter's book with skepticism, because heck, PHP is "just" a scripting language, and besides, Dreamweaver can write a lot of the code I need for myself.
But as I went through the book, I realized an object-oriented approach is a scalable approach. It can be applied to multiple projects. In essence, that's what Dreamweaver's doing when I tell it to write a recordset for me, and Macromedia's not doing too bad as a company... There are obviously benefits to be reaped from OOP in web development.
Lavin's book is great, because it walks you through and explains how OOP in PHP should work. He first explains the basics of OOP, then applies them to PHP, and provides real-world techniques and code to illustrate his points. He touches on AJAX, XML, RSS, thumbnail images, PDO, and other cool things in an approachable and understandable manner.
It's funny, but the illustration on the cover of the book says it all. Would you rather code a waffle from scratch, or code the wafflemaker, and make yourself waffles whenever you want them? That's the difference between just writing code and object-oriented programming. It gives you the power of reproducibility and scalability. So what are you waiting for? Get cooking with OOP!








Article comments
1 - Tom Minderson
"Reuse" has fallen out of favor as OOP's top selling point. And frankly, I don't know what the new selling point really is. Over time, OO proponents seems to slip further and further into subjective and evasive claims, sounding more and more like the cheesy eastern philosophy on the Kung Fu TV series. Reductionist science and OO seem worlds apart.
But if you want to stick with "reuse" as the primary claim of OOP, I challenge you to create a practicaly reusability code sample that procedural/relational cannot match. (Hint: in the real world, variations-on-a-theme rarely slice down nicely as a tree taxonomy over the longer run.)