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

Leave a Reply

Your email address will not be published. Required fields are marked *