PHP Design Patterns

Learning PHP Design Patterns, William Sanders, O’Reilly 2013

Web programmers will want to read this book, in particular users of PHP.

PHP’s success as a web app language comes largely from its freedom from structure: you can hack code together and do almost anything. But what if your app is large, you don’t want errors, and you want to understand it? Think of Vtiger, which combines (yikes) code from SugarCRM, Smarty, ckeditor, antlr, PearDatabase, adodb, freetag, nusoap, phpmailer, tcpdf, PDFMaker, htmlpurifier, php_writeexcel, kcfinder, log4php, AjaxUpload, HTMLSax3, iCal, qCal, PHPMailer, and Image_Graph projects, not to mention several Javascript libraries. The many subprojects are structured using Object Oriented (OO) concepts, which gives you a hope of understanding it.

To succeed in larger projects you need some structure, and PHP Design Patterns proposes that you use the same high level structures that have been useful to C++ and Java programmers for many years. The author read the ‘Gang of 4′ book (Gamma, Helm, Johnson and Vlissides), and has interpreted it in the PHP context. He starts with a refresher on Object Oriented programming, which will be easy reading for anyone with knowledge of OO. Then he shows how to make best use of the OO features in PHP since version 5, referencing the most useful design patterns. Inheritance, polymorphism, encapsulation are all discussed with example code in php.

Returning to the Vtiger example, when the code uses some OO structure, it is often not clear what pattern is in use. A file should start with comments on what design pattern is being used, and if not, then a discussion of how the objects are used. If the designers had started with the common design patterns from this book, then it would all be more clear.

I want you to read this well written book in the hopes that the next php projects I need to enhance will be well structured and easier to work with. This means you! Why would you not just Google The Fine Thing (GTFT)? Because then you get snowed with poorly edited info. Read the book for a well organized presentation of the few important, common patterns.

Disclaimer: I read the electronic version of the book, on a smartphone. The reading experience is quite different from bound, paper books with pros and cons. Disclaimer 2: I got the book through the O’Reilly blogger program.

If this book interests you, then you might also want to read Javascript patterns By Stoyan Stefanov for a complementary treatment of the client side language.

Unfortunately, the OPL does not have PHP Design Patterns yet. 350 pages.

Get it here at OPL     Amazon Review

Carleton Library     University of Ottawa

About rleir

I work at, automating the OCR (Optical Character Recognition) of archived documents. They have been photographed onto microfilm, then digitized to JPEG, then ingested into a digital archive. Millions of images need to be scanned for text. ------------------- I still have a small hand in CirrusComputing, which provides a Virtual Desktop. It provides all the business apps that a SMB needs, including LibreOffice word and calc, FireFox browser, Evolution email and calendar, vTiger CRM, and many other excellent collaboration apps. You are protected from Windows viruses and other malware because every app runs remotely in a Linux server. Use it from any PC wherever you are, and see the same desktop. Performance is snappy because of the NX communications, much faster than RDP or VNC. And backups are automatic, daily. Do not worry about power failures in your office, because you will find your desktop unchanged when your power is restored. I use it daily as my own work desktop.
This entry was posted in books and tagged , , , . Bookmark the permalink.

Leave a Reply