Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
Book Reviews Books Media

The PHP Anthology 2nd Edition 80

Michael J. Ross writes "When veteran PHP developers have specific and nontrivial functionality that they want to implement in their code, they can do so from scratch, but this can be time-consuming or essentially reinventing the wheel. They can adopt completed code posted in an online discussion forum, but such code tends to be buggy. They can use an open source library or other packaged code, but this approach can oftentimes prove to be overkill. Consequently, many developers prefer focused solutions found in PHP cookbooks, such as The PHP Anthology: 101 Essential Tips, Tricks & Hacks." Read on for the rest of Michael's review.
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition
author Davey Shafik, Matthew O'Phinney, Ligaya Turmelle, Harry Fuecks, and Ben Balbo
pages 542
publisher SitePoint
rating 9/10
reviewer Michael J. Ross
ISBN 0975841998
summary A tasty cookbook of PHP recipes
The second edition of this book was published by SitePoint on 23 October 2007, under the ISBNs 0975841998 and 978-0975841990. On the book's Web page, the publisher makes available an overview of the book, links to the authors' sites, chapter descriptions, the table of contents, the index, editorial and customer reviews, the book's sample code, and errata (there are none as of this writing). In addition, there is a link for downloading three sample chapters (2, 10, and 11), in PDF format. The pop-up window for entering an e-mail address for receiving the download link, also gives one a chance to subscribe to SitePoint's Web development newsletters.

All of the authors of The PHP Anthology — Davey Shafik, Matthew O'Phinney, Ligaya Turmelle, Harry Fuecks, and Ben Balbo — appear to have plenty of experience with the language, and probably also have spent time interacting with other PHP programmers in online forums, including SitePoint's own PHP forum. Experience reading the questions posted by programmers of all skill levels, and especially trying to answer them, can give anyone a better understanding of what are the most common challenges encountered by the typical PHP coder. In the book's preface, the authors note that, for choosing the particular problems for their book, they chose ones frequently seen in the SitePoint forum, which is likely representative of all active PHP forums.

This new edition of the book has been updated for PHP version 5, including PHP's major improvements to its implementation of classes and objects, among other aspects of the language. It is one of a growing number of PHP books that depart from the traditional tutorial and reference formats, and is instead written in the increasingly popular "cookbook style." Each section presents first a common problem that Web programmers often encounter, followed by generally complete source code that solves the problem, and commentary that explains the overall solution, along with special considerations that the programmer should watch out for in adapting the given source code to their own situation.

As seen in the majority of cookbook-style programming books, this one groups the problem-and-solution sections into chapters, of which there are 13: an introduction; working with databases using the PHP Data Objects (PDO) extension; strings; dates and times; forms, tables, and clean URLs; files; e-mail; digital images; error handling; access control; client- and server-side caching; XML and Web services; PHP coding best practices. In addition to the preface and index, the book also has four appendices: configuring PHP; a checklist for choosing a Web hosting service; a security checklist; and working with the PHP Extension and Application Repository (PEAR). In total, the book is 542 pages long, and yet it is not visually overwhelming, partly because of the large and readable font chosen by the publisher, as well as the innumerable code snippets and browser screen shots interspersed throughout the narrative.

The primary strength of this book is the significant amount of information provided to the reader, in the form of summaries of critical Web programming problems, working PHP code that addresses those problems, discussion as to why each particular approach was taken, and occasional asides that warn the reader about special difficulties that they might encounter as they implement the solutions within their own development environments and for their own projects. Some of the material may be of little interest to the average reader — such as the chapters on PDO and XML — but most of the material would be of interest and benefit to any conscientious PHP programmer. The chapters on error handling and access control are alone worth the price of the book.

However, this second edition of the book has some weaknesses that may or may not have been introduced since the first edition (which was not readily available for comparison). But none of them are overwhelming or unfixable. Firstly, a reader hoping for a well-edited book will likely become distrustful by the authors' misuse of the term "that" in place of "who." Secondly, there are far too many ambiguous comments in the first-person, e.g., "I would dare to say that..." In a book written by five authors, the reader naturally has no idea who is speaking. Thirdly, there is a fair amount of inconsistency in the formatting of the code throughout the book, including indentation and other spacing, as well as variable naming. Also, every instance of a "{" on its own line (presumably to line up vertically with the corresponding "}"), is an antiquated waste of space, since any decent programmer's editor or integrated development environment (IDE) can do brace matching automatically.

Lastly, almost all of the section titles begin with the phrase "How do I." That is fine within the body of the book, at the beginning of every section. But when dozens of these section titles are listed together in the table of contents, that phrase could be excised so each section's topic would be faster to spot, and there would be fewer unnecessary words. In fact, the section titles don't necessarily have to be posed as questions. For instance, "Using Sessions" would be just as clear as "How do I use sessions?" and faster to read.

It should be noted that this book is best suited for intermediate to advanced PHP programmers, who will certainly get the most out of it. A programmer new to PHP, who would like to begin learning the language, should start with any one of the many tutorial-style PHP books available.

For readers who prefer the portability or environmental benefits of e-books, a PDF version of The PHP Anthology is available from the publisher, on the aforesaid Web page. Any programmer who is — or anticipates — doing PHP work away from their print technical library, should definitely consider obtaining the e-book, which thus can be added to their laptop's development environment, and be readily available for quick reference. The e-book contains all of the content of the print version. It also makes good use of color, for screenshots and other illustrations, as well as using a blue background for the sample code, which is a bit easier to read than the gray used in the print version.

Overall, this new edition of The PHP Anthology offers practical solutions to many common PHP problems, clear explanations of those solutions, and working code — in print and online — that can be quickly used as is or modified as needed. PHP developers should find this book an informative and valuable part of their technical library.

Michael J. Ross is a Web developer, writer, and freelance editor.

You can purchase The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

The PHP Anthology 2nd Edition

Comments Filter:
  • by Anonymous Coward on Wednesday November 28, 2007 @04:28PM (#21509251)

    Warning, this is a goatse.

  • by corychristison ( 951993 ) on Wednesday November 28, 2007 @05:02PM (#21509731)
    Disclaimer: The opinions expressed in the following comment are of my own. Please do not flame or complain because I do not share the same opinion as you.

    PHP is not that bad of a language. Yes, it has it's issues and has brought on it's own stereotype because of it's ease of use. But really, when it comes to getting things done and done quick.. PHP excels very well.

    I use PHP on a daily basis. Not just for work (I am a web developer by profession), but for quick dirty hacks (especially when bash is not available) it is great too. I've written entire daemons that watch and entire directory tree (1000+ files) and will alert me in some way of something happens, etc. I've written a IRC-style chat system way back in the day, and so on.

    PHP has GTK [php.net], and apparently QT [php-qt.org] (server appears to be down ATM) bindings now. It has a lot of really useful low-level bindings, such as FAM [php.net]. Along with Sockets and friends PHP is very powerful. Especially if you can get out of the mentality that "PHP was designed for websites." :-)

    PHP really has evolved... I am very greatly anticipating the upcoming PHP 6. NAMESPACES! I can't wait.

    I've used and worked with Ruby, Python, TCL, etc. etc. PHP just sits right with me.
  • by CastrTroy ( 595695 ) on Wednesday November 28, 2007 @05:45PM (#21510311) Homepage
    A lot of the free online tutorials don't show best practices though. How many tutorials have you seen for PHP + MySQL where it wasn't shown that you should construct queries by concatenating strings with either not escaping quotes, using your own function (because the author has no clue that a proper function exists), using mysql_escape_string (which is deprecated), or using mysql_real_escape_string. The right answer is that in the majority of cases, people should be using prepared statements, so that they don't have to worry about whether or not they are escaping strings properly. Granted I think a lot of books get this wrong to, but most of the tutorials I've seen on the web are even worse. Most of the tutorials are extremely low quality, and I wouldn't recommend that anybody trust them as a place to learn how to write good code.

    To point out how bad tutorial code on the net can get here is a little analogy. I was once looking up how to make a timer in VB.Net go off at a certain clock time, when the only argument is would accept is number of milliseconds until it goes off. I found a number of tutorials on the internet that said I should set it to 1000 milliseconds (1 second), and then just have it go off, check if it's the right time, and proceed if it is. I couldn't find anything on the web that pointed out a better solution, but I know there had to be one. Finally I figured out that if I did TimerRunTime.Subtract(Now).TotalMilliseconds, I would do exactly the thing I was looking for, without having the timer go off every second, and actually using less code.
  • by JewGold ( 924683 ) on Thursday November 29, 2007 @12:50AM (#21514299)
    try {
                    @eval("-=-=-=- INVALID SYNTAX GOES HERE -=-=-=-");
    } catch (Exception $e) {}

    echo "Yay, I'm still here!!";
  • by Blobule ( 913778 ) on Thursday November 29, 2007 @01:59AM (#21514829)
    Get with the program please: http://www.php.net/manual/en/function.eval.php [php.net]

    Return Values

    As of PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler()

Genius is ten percent inspiration and fifty percent capital gains.