Core PHP Programming 2/E Errata

These are the bugs found so far in the second edition.


Erik Wiersma pointed out that the postForm function that’s part of
the BBS example in Chapter 17 uses $PHP_SELF, but can’t actually get
to it without first declaring it as a global. This is listing 17-7
on page 636. Please add


to the top of the function, before the first print statement.

Thanks, Erik!


Richard Tape noticed that Listing 15.1 on page 582 has a missing dash in
its for loop on line 11. The correct line should be

for($position = $limit-1; $position >= $bubble; $position--)

Thanks, Richard!


Dan Barber used the session-handling code in Chapter 17 (Listing 17.5,
page 631) in a live site, which is cool except for one issue. The random
number generator is being seeded with the output of time(). This is
the number of seconds on the clock. So, if two people request a session
identifier during the same second, they’ll get the same identifier. That’s
not good at all.

The fix is to use something that will change a lot more often. I suggest
using (double)microtime()*100000000.00 in place of time(). But let me stress
that it’s probably better to use the built-in session handling available in
PHP 4.

Thanks, Dan!


Alvin Koh pointed out that Figure 7.2 is labeled correctly, but it’s the wrong
code. It should be demonstrating environment variables. The file on the CDROM
is correct. Here’s what it should be in the book:

Thanks, Alvin!


Anthony Boyd discovered the glaring error in Listing 15.6. The code there is not
right at all! Here’s the correct example:

Thanks for bringing this to my attention, Anthony!


Andrew Harrowing pointed out a typo in the example on page 514. Change the line
that reads




and it will really print out the message body. Thanks, Andrew!


Murray Moffatt wrote to tell me about the missing right parenthesis in the code
on page 207. Thanks, Murray!


Murray Moffatt also notified me that imagejpeg() now uses quality values from 0 to 100.
Page 367 describes this function. Thanks again, Murray!


Dave Patton sent me these tidbits.

Page 67, mid-page, “Chapter 20” should be “Chapter 21”.

Page 175, last line “Chapter 21” should be “Chapter 22”.

Page 242, the comment “//set up array of color names” in the array_values example belongs with the array_walk example.

Page 267, strspn, “position in the” should be “position of the”.

Page 276, Table 9.5, many of the entities are listed twice.

Page 394, dba_open, reference to Table 13.3 refers to “four types”, but Table 13.3 on next page lists five types.

Page 628, last paragraph, refers to database “store”, but example on prior page uses database “test”.

Page 714, last paragraph, URL contains
“21-5.php”, but example is talking about “21.3”. On the next page the script is referred to as “21-5.php”, but again, the listing is numbered 21.3, and the screen print shows the URL containing “21-3.php”.

Thanks, Dave!


Krishnan Renjith found an error in the example style guide.

On page 746, there’s a while loop that should be a for loop.

while($index = 0; $index < count($userName); $index++)

should be

for($index = 0; $index < count($userName); $index++)

Thanks, Krishnan!


Matt Sadowski found a bug in the example for array_splice on page 241.

array_splice($colors, 2, 2);

should be

array_splice($colors, 2, 1);

The description of this function talks about the third argument being
positional, but today it’s clearly a length argument.

Thanks, Matt!


Stuart Cooper pointed out that the book refers to a “tertiary” operator,
instead of a “ternary” operator. Of course, “tertiary” means third. “Ternary”
means having three parts and is the correct way to describe the ?: operator.
Alternatively, this operator could be described as “trinary”.

Thanks, Stuart!

One reply on “Core PHP Programming 2/E Errata”

In the section on “Receiving User Input”, pages 18-21, you need to change the last sentence on page 19 as follows: “When the user presses the submit button, the script named in the ACTION attribute will receive the three form fields and PHP will convert them into variables, accessible by the associative arrays $_POST[ ] and $_GET[ ], depending on whether the FORM METHOD is post or get.”

On page 20, the script “1-5.php” should contain the three accesses to the form variables are follows:

$YourName = $_POST[“YourName”];
$CostOfLunch = $_POST[“CostOfLunch”];
$DaysBuyingLunch] = $_POST[“DaysBuyingLunch”];

You need to do this before you can even use these variables in the rest of the script.

Leave a Reply

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