Oakland.pm

Reviews

Review of "Programming PHP"

author: Rasmus Lerdorf, Kevin Tatroe

reviewer: George Woolley


Programming PHP
By Rasmus Lerdorf, Kevin Tatroe
First Edition March 2002
ISBN: 1-56592-610-2
528 pages, $39.95 US, $61.95 CA, £28.50 UK

Short Review

Rating: :) :) :) :) of 5

PHP is a programming language that can be embedded in web pages. It makes it significantly easier to develop and maintain web pages.

This is a clear, well-organized reference manual for PHP 4. I've found it very useful.

It is not a tutorial for PHP. It does not cover PHP 5.

If you wish, checkout my somewhat longer review

Miscellaneous

List of Chapters

  • 1. Introduction to PHP
  • 2. Language Basics
  • 3. Functions
  • 4. Strings
  • 5. Arrays
  • 6. Objects
  • 7. Web Techniques
  • 8. Databases
  • 9. Graphics
  • 10. PDF
  • 11. XML
  • 12. Security
  • 13. Application Techniques
  • 14. Extending PHP
  • 15. PHP on Windows
  • A. Function Reference
  • B. Extension Overview

Notes:

Online Watch

Safari logo image

This book is available on Safari Technical Books Online, if you happen to be subscribed to that service. Actually, I began reading the book on Safari; but when I saw how good the book was, I bought it.

Online Manual: If you want an on-line manual in English, I suggest trying the Online Manual on the PHP.net site. If you wish a different language and/or a different format, see PHP Documentation for a number of choices.

Some good things about the online manual are:

  • It's (duh) online.
  • It's free.
  • It covers both PHP 4 and PHP 5.
  • It includes user contributed notes.

Some not so good things about the online manual are:

  • It goes into more detail than you may wish to deal with
  • It doesn't give a lot of perspective.

Online Tutorial: If you want a tutorial, I suggest trying Getting Started PHP Tutorial on PHP.net.

Online Searches: There's lots of PHP stuff on the web. Here's some sample searches:

   site:php.net php manual 
   site:php.net php tutorial 
   comparison php perl
   php regular expression function

PHP Fun

A Name That's Fun: The very name of PHP is fun in a geekish kind of way. It's a recursive name in the spirit of GNU. GNU stands for "GNU's not UNIX". PHP stands for "PHP: Hypertext Preprocessor".

If you think of that in the right way (wrong way?), does that mean that, among other things, PHP stands for the following?:
    PHP: Hypertext Preprocessor Hypertext Preprocessor

A Fun Blog by PHP Royalty: For a fun blog by a PHP princess, visit the Geek Fun & Humor category in the archive of a certain princess named Daynah.

A Fun Page Written in PHP: You might enjoy Random Geek Fun which is my first attempt at something in PHP that's on the net.

Somewhat Longer Review

Contents

Note:

What's PHP?

PHP stands for PHP: Hypertext Preprocessor. ;-)

PHP

  • is a programming language
  • is open source
  • is easy to learn
  • is easy to read
  • runs on the server side
  • can be embedded in web pages
  • makes creating maintainable web pages much easier

There have been several versions of PHP. The versions you definitely need to be aware of are PHP 4 and PHP 5.

PHP 4: PHP 4

  • was first released May 2000.
  • is installed on many servers.
  • is stable.

PHP 5: PHP 5

  • was first released July 2004.
  • has many improvements, most notably an improved object model and some new OO features.

Hello World in PHP:

<html>
<head>
   <title>Learning PHP: hello world!</title>
</head>
<body>
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->

   <?php
      echo "<p>Hello World!</p>";
   ?>

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
</body>
</html>

About the Reviewer

Databases: I've done very little with databases.

My ISP does not provide me with MySQL which is often used with PHP.

Languages: I've made significant use of over 20 different computer languages. Not surprisingly, I'm good at learning computer languages.

O'Reilly: I own many O'Reilly books. I am generally quite satisfied with them. I'm a fan of O'Reilly.

Perl: I've been using Perl since 1994. My favorite language by far is Perl. Over the years, I've written a number of Perl CGIs.

I've used Perl a lot in my work and had one job where I worked entirely in Perl. However, I don't consider myself an expert in Perl.

PHP: I've only recently started to use PHP and have only used it a little. See A Fun Page in the left column.

I have some advantages for learning PHP

  • I already know Perl which is similar in many respects.
  • I am quite familiar with the web which is what PHP focuses on.
  • I've had a lot of practice learning computer languages.

My ISP does provide me with PHP 4 and it is now enabled for my domain.

Webmaster: I've developed a number of websites and am currently the webmaster of several non-profit sites. I am definitely not a professional webmaster.

What I Expected

Reference: Based on the title of the book and on the Preface, I was expecting a language reference.

PHP: I was expecting the book to be focused on PHP, or, more specifically, PHP 4.

What I Got

What I got and what I think you'll be getting if you get this book is a well-organized, well written reference manual for PHP 4.

Two Main Parts: I see the book as consisting of two parts

  • language basics, including chapters 2-6 and appendix A
  • more advanced topics, including chapters 7-15 and appendix B

See List of Chapters in the left column for the names of the chapters and appendixes.

Language Basics: If you are like me and fairly new to PHP, I suggest working through the first 6 chapters and scanning appendix A. If you do, by the time you finish working through what I refer to as the basics, you should have a handle on the following in PHP (among other things)

  • variables (2), operators (2) and expressions (2)
  • various data types (2) including strings (4), indexed arrays (5) and associative arrays (5)
  • flow control (2), functions (3), includes (2)
  • the functions that are standard with PHP (A)
  • objects (6)
  • embedding PHP in web pages (2)

The numbers in parentheses refer to chapters (or appendixes).

More Advanced Topics: There are 9 chapters and one appendix on more advanced topics.

Depending on your purpose, you can pick and choose between the more advanced topics. I focused on

  • web techniques (7)
  • security (12)
  • application techniques (14)

As above, the numbers in parentheses refer to chapters. You likely will have different interests.

For a list that includes all the advanced chapters, see List of Chapters in the left column.

What I Liked

Using the Book as a Reference: I first used this book as a reference when I started learning PHP. The parts I looked at were unusually clear. It didn't seem to matter that I was new to PHP.

The index served me well and, generally, I was able to quickly find what I wanted.

Learning Specific Functions: I've learned a number of specific functions from the book that I expect to be quite useful. For example:

  • error_log which will be handy for reporting errors
  • implode which will be handy for putting back together strings that have been split into pieces
  • var_dump which will be handy for displaying variables (especially associative arrays) during debugging

Learning how to Embed PHP in Web Pages: I enjoyed learning how to embed PHP in web pages. Here's an example of such embedding.

Example:

<?php
   $title = "Embedding HTML";
?>
<html>
   <head>
      <title><?=$title; ?></title>
   </head>
   <body>
      <p>Hello PHP World!!</p>
   </body>
<html> 

Notes on Example:

  • In the structure <?php ... ?>, the ... is PHP code. Strings can be printed in the ... and become part of the HTML. In this case, the code is a single assignment of the variable which will be used for the title of the page.
  • In the structure <?= ... ?>, the ... is a PHP expression. The evaluated expression becomes part of the HTML. In this case, the expression is a simple variable which holds the title of the page.
  • The output shown is the HTML the server would see (minus the header). The user at his/her browser would see whatever that HTML generates.
  • This example doesn't do anything useful other than illustrating two ways to embed PHP code.

Output from Example:

<html>
   <head>
      <title>Embedding HTML</title>
   </head>
   <body>
      <p>Hello PHP World!!</p>
   </body>
<html> 

Learning about Strings: Most of the programs I write are focussed on strings. The book has a whole chapter on strings. Some of the the things I learned regarding strings in PHP in that chapter or elsewhere in the book were:

  • various ways to quote strings
  • how to interpolate
  • various ways to print strings
  • how regular expression are used
  • how to split a string into pieces, process the pieces and put the string back together

Example:

The following example illustrates various styles of quoting, interpolation and printing.
<html>
   <head>
      <title>PHP Strings</title>
   </head>
   <body>
   <?php
      $verb        = 'Hello';
      $noun_phrase = 'PHP World!';
      $message     = "$verb $noun_phrase";
      echo "      <p>$message Once</p>\n";
      echo <<< ENDIT
      <p>$message Twice!!</p>
      <p>$message Thrice!!!</p>
      <p>$message Infinity Times!!! ...</p>

ENDIT;
   ?>
   </body>
</html>

Notes on Example:

  • The <<< indicate that a here document follows. In this case, the here document is ended by ENDIT.
  • Within the double quotes and in the here document, variables are interpolated, that is, the variables are replaced by their values. E.g. $verb becomes Hello.
  • The output shown is the HTML the server would see (minus the header). The user at his/her browser would see whatever that HTML generates.
  • This example doesn't do anything useful other than illustrating some things you can do with strings in PHP.

Output from Example:

<html>
   <head>
      <title>PHP Strings</title>
   </head>
   <body>
         <p>Hello PHP World! Once</p>
      <p>Hello PHP World! Twice!!</p>
      <p>Hello PHP World! Thrice!!!</p>
      <p>Hello PHP World! Infinity Times!!! ...</p>
   </body>
</html>

Gripes

Introduction: Parts of the Introduction were harder for me to read than the chapters that follow. I'd prefer a less demanding introduction.

Lightness: There is little humor in the book. Oh, well! The book is not heavy, but rarely is it light hearted.

Hey, PHP has it's lighter side. See PHP Fun in the left column.

Search Difficulty: I was uncertain what <?= meant? I looked it up in the index, but did not find it. :-( I looked around for it a tad more in the book and then tried unsuccessfully on the web. :-(

But this story has a happy ending. I eventually found an explanation of <?= in the book. :-)

As far as I recall, this was the only case where I had noticeable problems finding what I was looking for.

Who's the Book for?

For: I would say the book would be best for someone who

  • either has already used PHP a moderate amount or is an experienced programmer
  • and has a basic knowledge of the web and of HTML and it's use.

Not For: Some reasons you might not want this book are:

  • You want a book that covers PHP 5.
  • You want a tutorial.
  • You want something free.

Although much of the book is fairly easy to follow, it's not a good choice for someone looking for a tutorial. It's just not written to ease the reader along. For example, parts of the Introduction are more demanding than most of the detailed chapters. Generally the book is just too concentrated for a beginner.

Final Thoughts

If you are serious about PHP 4 and you need a reference, this is a well-organized, well written reference. Go for it.

While this reference manual is quite clearly written, I don't recommend it as a tutorial. I also don't recommend this book if you need something covering PHP 5; it doesn't address PHP 5.

Draft First Uploaded: 2005-06-10

Completed: 2005-06-20