review : programming php, 2e - Lerford, Tatroe, and MacIntyre

Audience: Strong programmers new to PHP but not anyone in need of a core reference.

It seems an appropriate time for me begin exploring PHP after a great deal of reluctance. I think my reluctance stems from experience. I have mastered several languages in the past but find, as is the case with technology, you learn them for a purpose. Once that purpose has passed, you quietly move along to the next. It seems I now have some sense of purpose for PHP as I want to improve – or perhaps ‘customize’ is the better word – the utility of wiki tools (like MediaWiki) and blogging tools (like WordPress which powers this blog.)

To this end, I recently picked up the book Programming PHP, Second Edition by Lerdorf, Tatroe and MacIntyre. Not being one to read programming books linearly – or even in any orderly fashion – I put the book by my side as I began hacking at the source code for WordPress and K2 (the starting point for my theme). For a PHP n00b, the book is proving to be a good resource.

The next morning over coffee I decided to read a few chapters as they were written. In the preface the authors identify the target Audience: “If you’re a programmer, then this book is for you.” (p. xii). This is subtle. As an experienced programmer, I found the book a good starting reference. If you are a novice programmer, this book will be a challenge. (I realize the adjective “novice” provides only a modest refinement of the authors’ statement but it nonetheless is a refinement.)

Chapter 2 is definitely not for the faint of heart. It provides a very direct delivery of the language basics. For the experienced programmer, this is nice. The challenge to the novice is in how the authors use constructs before they are completely defined. This is the typical chicken-egg problem with programming texts. To define everything before you use it makes for very long and rather boring chapters, to consolidate means forward referencing. As I would always recommend, read the whole chapter before you get too frustrated. On the other hand, this chapter also contains typos. In some cases you aren’t sure if something is a typo or just a forward reference. This could somewhat be mitigated by a more complete index, especially with respect to symbols.

The authors regularly intertwine source code and the result of the code’s execution in code samples. For example, when discussing variable references in chapter 2, the provide the following example (p. 32):

$big_long_variabe_name ="PHP";
$short =& $big_long_variabe_name;
$big_long_variabe_name .= " rocks!";
print "\$short is $short\n";
print "Long is $big_long_variabe_name\n";
$short is PHP rocks!
Long is PHP rocks!
$short = "Programming $short\n";
print "\$short is $short\n";
print "Long is $big_long_variable_name\n";
$short is Programming PHP rocks!
Long is Programming PHP rocks!

In other cases, all of the PHP code is written and then all of the output. While not impossible to read, it takes a bit to digest cleanly – especially when syntax is the focus of the discussion. The benefit is in the abbreviation of the code-to-output explanation.

Chapters 3 though 6 cover Functions, Strings, Arrays and Objects, respectively, and are similarly terse. That is, the book gives you the basics but in some cases leaves you with questions. As the book delves into the more rich topics in the later chapters which include web techniques (handling of forms, sessions, etc.), databased interaction and security issues as well as working with graphics, PDF and XML, the book begins to really come in to its own. The final two chapters become of interest after you’ve gained some experience and discuss how to effectively use PHP as well as extending PHP.

I did find that the brevity of the initial chapters left me with numerous questions about the language itself. For example, exactly what value can a variable take on that can’t be interpreted as a boolean; i.e., what purpose is the is_bool() operation? This isn’t inherently bad as it forces me to write example scripts to figure it out.
The book does have an appendix with the function reference for PHP 5. Personally, I find that a plus.
Overall though if you are looking for a book introduction to PHP that will serve you well until you start rolling your own wiki or blogging tool from scratch, this book is a solid recommendation.

No comments:

Post a Comment