Book Review: Object-Oriented Programming with PHP5

June 23, 2008

Uncategorized

Object-Oriented Programming with PHP5

Title: "Object-Oriented Programming with PHP5"
Publisher: Packt Publishing Ltd.
Publication Date: December 2007
Author: Hain Hayder
Pages: 249
Price: $39.99

Overview

"Object-Oriented Programming with PHP5" is aimed at beginning or mid-level programmers that want to expand their knowledge of object-oriented features in PHP. Although basic OOP support was present in version 4 of PHP, it wasn’t until the introduction of version 5 that they caught up with object-oriented implementations of other popular languages, such as Java or Python. The book does a decent job of covering the main OOP topics in PHP; as well as, touching upon some of the peripheral ones. Hayder devotes whole chapters to such topics as unit testing, design patterns, XML, SPL, and working with databases.

The Good

I like how there are plenty of examples throughout the whole book. This is definitely a how-to of OOP in PHP5. As is typical in books of this type, none of the examples are meant to be ready for a productions system, but most are good starting points for the reader to develop his or her own solution. In my opinion, this approach is right in line with the intended audience.

Another aspect I really liked was that the author devoted a whole chapter to SPL (Standard PHP Library). This collection of classes and interfaces is an often over-looked treasure trove of functionality and convenience for anyone writing code in PHP. Unfortunately, the available SPL documentation is nowhere near as accessible as the main PHP manual, which is probably why even many professional programmers don’t know that SPL exists. Or, if they have heard of SPL, they don’t know how to use it. Either way, this is a splendid group of utility classes and I’m glad that the author chose to give it the attention it deserves.

The Bad

There are a number of smaller gripes I have with this book. These are things I wouldn’t necessarily consider deal-breakers, but they nevertheless distract from the main focus. I don’t really fault the author for these, but in my opinion these are issues that should have been addressed by the editor and technical reviewers of the book. For starters, it is pretty obvious that the book was authored by someone whose first language is not English. It is riddled with odd expressions, such as “you can make take advantage,” “did you get the catch”, or “this cool set of API” British spelling (“favourite”) and terms such as “fresher” abound.

The author uses some notation and conventions in his code where I would have preferred to see a more standard approach. For example, nearly all sample code is enclosed by the short opening and closing PHP tags (“<?” and “?>”); whereas, a full tags would have been more appropriate (“<?php” and “?>”). Actually, the often preferred way tag style is to use a full opening tag and omit the closing tag altogether (honest – look it up if you don’t believe me). Also, he names all his classes using the convention “class.NAMEOFCLAS.php” (which he doesn’t even follow consistently throughout the book). Here, I would have preferred path and naming conventions used in the Pear Repository or the Zend Framework.

Some topics that would have deserved more attention are simply brushed over. UML, for instance, cannot be explained in half a page. Class diagrams and hierarchies are often an essential part of OOP and consequently deserve more attention. At the very least, the could have listed some additional resources for the reader to do his own research on UML.

I his chapter about working with databases, Hayder looks at both Mysqli and PDO in some detail. However, I would have really liked a short explanation of the differences in these two libraries. If you ask an experienced PHP programmer, he will tell you that the two have various pros and cons that one needs to be aware of before building the rest of your application on top of it.

The Ugly

Aside from the smaller issues mentioned above, I have some major complaints that are pretty unforgivable in a book aiming to teach other programmers. For example, in chapter 4, Hayder introduces design patterns, one of the most well-known of which is the Singleton pattern. Unfortunately, the Singleton implementation the author chose for his book is not only non-standard, but it is completely flawed. Any unsuspecting reader using that implementation in his or her own code might end up with serious memory leaks and bugs that will be very hard to track down.

Although I welcome the many code samples, the lack of explanations and commentaries is a major problem. Time and time again, the author chose to give pages of examples, but no explanation or discussion. As a matter of fact, there is a lack of depth and breadth that permeates the whole book. On one hand, if you want to learn that certain features exist and see a simple example (but little explanation) of how to use them, this book is for you. On the other hand, if you are looking for a comprehensive treatise and in-depth look at some of the more intriguing object-oriented features of PHP5, keep looking. I’m afraid to say that “Object-Oriented Programming with PHP5″ offers little above and beyond what you can find in the excellent online manual at php.net. In particular, if you want to brush up on PHP5′s flavor of OOP, you should start at the OOP5 page on php.net.

Summary

There is no question that object-oriented programming is the future of PHP. With the PHP point releases solidifying and adding to these features and with PHP6 on the horizon, any programmer serious about coding in PHP should master these tools. Although a decent starting point, "Object-Oriented Programming with PHP5" is far from what could be considered comprehensive. Moreover, some serious flaws are responsible for the book not quite delivering on its promise.

There are many interesting titles in the area of Open Source and PHP in Pack Publishing’s catalog; unfortunately, I don’t think that this is one of the better ones.

One Response to “Book Review: Object-Oriented Programming with PHP5”

  1. crazymerlin Says:

    I got a copy of this against my own better judgment.
    I do not know why but something just said…moo!
    Personally I think I could have written something better, or at least as good, on a Saturday afternoon. It simply lacks, in every area.

    I have found that the 2 books I have purchased from PAKT seem to lack everything except repetition. Many pages are filled with code from previous sections instead of "see code in section 2.1". This gives the books extra content, but only of code you do not need…more than once at least.

    Want a good PHP5 OOP book?

    The best I have in my extensive collection is "PHP5 Power Programming" written in part by Andy Gutmans.