Let me start off straight away by saying this is not a book for people who are new to PHP. As with other books in the Cookbook series, such as the Java Cookbook that was previously reviewed by TPC, this book is different in its aim and its structure to most other computer programming books. It is not about teaching you how to program but is a book for people who have understood the mechanics of PHP programming (or who will be using other resources to understand the mechanics of PHP). It is a reference book for use when embarking on your first project using PHP and for use thereafter. Its structure is simple and to the point, consisting, for every task detailed,of a statement of the problem, solution, a discussion of the solution and “see also” references.

What’s Covered

Areas covered in this book are Strings, Numbers, Dates and Times, Arrays, Variables, Functions, Classes and Objects, Web Basics, Forms, Database Access, Web Automation, XML, Regular Expressions, Encryption and Security, Graphics, Internationalisation and Localization, Internet Services, Files, Directories, Client Side PHP and PEAR. Each area has a chapter dedicated to it. In each chapter between 9 and 27 problems are addressed with a solution including working source code downloadable from the book’s web site. They really have crammed a lot into this book. Topics covered are diverse and the tasks covered range from the very simple to very advanced.

Although there is a discussion of solutions for each problem these are kept brief. You are referred to the appropriate section of the PHP manual or other appropriate online sources for more information. Essentially the book can be seen as a collection of sign posts and usable bits of code to get you started when you are looking for a solution to a problem you might spend quite some time looking for elsewhere. Many of the problems selected in the book are ones that you would not find solutions to elsewhere so easily.

Many of the topics covered seem to have been selected on the criteria that the authors feel they have something to offer the reader that will have not been covered in basic texts. On the other hand some of the problems solved in this book are certainly covered in every basic book on PHP programming; most tasks that you will regularly encounter as a PHP programmer have their solutions in this book. Solutions offered are often elegant solutions to a task that comes up again and again. Or they might be rather obscure and non intuitive but simple solutions to tasks that you are likely to want to perform in your scripts.

Good Points

The kind of information contained in this book could be more easily referenced and searched online. Certainly such resources do exist on the Internet but since the contributors to these projects are unpaid volunteers it becomes necessary to sort out the chaff from the wheat when using such resources. Thus many searches for a solution to a problem may involve exhaustive work searching through many different sources of information. This book is authorative and trustable in a way that is often lacking in online tutorial repositories or similar, and is more comprehensive and consistent than any online repository I have come across. Of course it will probably go out of date in a year or so at which time it will be necessary to buy another similar book.

I have found myself referring to this book again and again when programming with PHP. It is a great companion for the programmer looking for solutions and is a good first source to turn to in many cases. You can quickly find solutions to all sorts of things you want to do with your script. It is more useful than the books I bought that taught me the basics of PHP programming for reference purposes, because it dispenses with going into too much detail about how everything works, which is not what you need at a more advanced stage. You can use the PHP manual or other online resources to find out about the syntax of the functions used by the scripts in the book, for example: a lot of info from the PHP manual would be replicated in many beginner books.

Not-so-Good Points

Not everything is covered in this book. Since this book was written mainly, I suspect with an American or other Western audience in mind the coverage of localisation/internationalisation is not exhaustive. There is a quick mention of how to decode/encode from European ISO 8859-1 to UTF-8 characters. I would liked to have seen more detail in this section of the book. This is not just a failure of this book, though. I would very much like to find a good tutorial which would step me through all the different character escaping and character sets used in a typical HTML/PHP/MySQL application and how to get them all working properly together so that they can correctly display complex character sets such as Japanese without any surprises. This still seems to be a specialist topic although many application programmers are now providing some support, for non-European character sets such as Korean, Japanese, Chinese, etc.

One other problem with the format of this book is that in this book problems have only one solution. This is quite different to the world of PHP where there are many different solutions to one problem. Solutions found in this book are intended to be best practise. Most of the time this will probably be true. Programmers will however find that when reusing some of these solutions in real-world situations the solutions of this book will not always be best practise. If the rest of your site uses, for instance, one database abstraction library then it would not make much sense to use another library in just one part of the site. Examples given in the book should on the whole work well together but code you may get from other sources will not always fit so well with code from this book.

Conclusion

You will certainly need another book or maybe two to accompany this very useful book from O’Reilly. Other books I would recommend are Core PHP Programming or perhaps one or two of the excellent WROX press books on PHP Programming such as the excellent Professional PHP4 programming. Also if you are going to be programming with PHP you should download and install the PHP manual on your computer from PHP.net, install a version including user comments as they can often be quite useful and fill holes in the manual.

I would say this book is a good buy if you are beginning to put together web sites using PHP. This book will, hopefully, save you many hours of searching online for equivalent solutions and will probably result in web sites that are better coded and more robust.