PHP Cookbook

Errata for PHP Cookbook

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
Printed
Page xvii

"XML-RPL" NOW READS "XML-RPC"

Anonymous    Feb 01, 2003
Printed
Page xx
Acknowledgments

"Thanks also our reviewers" NOW READS "Thanks also to our reviewers"

Anonymous    Feb 01, 2003
Printed
Page 2
Table 1-1

The escape sequences { } [ ] are incorrect.

Anonymous   
Printed
Page 6
4th line of code under Discussion

// NOW READS: /*

Anonymous    Jan 01, 2004
Printed
Page 6
5th line of code under Discussion

*/ HAS BEEN ADDED to end of line.

Anonymous    Jan 01, 2004
Printed
Page 7
all comment lines in code

Spurious // HAS BEEN DELETED from the end of each comment line

Anonymous    Feb 01, 2003
Printed
Page 36
1st paragraph in 2.11 Discussion

The return values, not the arguments, for asin(), acos(), and atan() are in radians. The arguments for these functions are dimensionless. NOW READS: "These functions assume that all angles are in radians, not degrees."

Anonymous    Feb 01, 2006
Printed
Page 37
2.12 Solution code

NOW READS: $cosine = cos(deg2rad($degree)); $degree = rad2deg(acos($cosine));

Anonymous    Feb 01, 2006
Printed
Page 49
table 3-3

Minute %M I should be lowercase i

Note from the Author or Editor:
This was an error in 1ed, fixed in 2ed.

Anonymous  Jul 18, 2008 
Printed
Page 49
Table 3-3 in the date() column for the minute row

I NOW READS: i

Anonymous    Apr 01, 2005
Printed
Page 73
line 19 of the code

print "</tr> "; if ($day < $totaldays) { print '<tr>'; } NOW READS: if ($day < $totaldays) { print "</tr> <tr>"; }

Anonymous    Apr 01, 2005
Printed
Page 75
top of the page

"Chapter 4" was listed twice at the top of the page. This HAS BEEN CORRECTED.

Anonymous    Feb 01, 2003
Printed
Page 77
1st paragraph

"overwrites the value of 'Apple'. NOW READS: "overwrites the value of 'Apples'.

Anonymous    Jan 01, 2004
Printed
Page 93
Recipe 4.11

The order of the parameters were also inversed for in_array, first code line under Solution: NOW READS: if (in_array($value, $array)) {

Anonymous  Apr 20, 2009  Feb 01, 2003
Printed
Page 94
Recipe 4.12

The order of the parameters of the function were inversed. array_search ($array, $value) NOW READS: array_search ($value, $array)

Anonymous  Apr 20, 2009  Feb 01, 2003
Printed
Page 97
1st full sentence at top of page

The code shown finds only the value of the largest element, not the index as advertised. Additionally, it takes O(n log n) time, but it takes only O(n) time to find the largest element and its index using a simple algorithm: $ind = 0; for ($i = 1; $i < count($array); $i++) if ($array[$i] > $array[$ind]) $ind = $i; // $ind now contains the index of the maximum element

Anonymous   
Printed
Page 107
IN PRINT: Solution - line 4

array_intersection() NOW READS: array_intersect()

Anonymous    Feb 01, 2003
Printed
Page 126
bottom of the page

See Also Recipe 10.7 for information on escaping data for a database NOW READS: See Also Recipe 10.9 for information on escaping data for a database

Anonymous    Apr 01, 2005
Printed
Page 167
See Also

"Recipe 7.11 for defining a call dynamically" NOW READS "Recipe 7.12 for defining a class dynamically"

Anonymous    Feb 01, 2003
Printed
Page 197, 198
Recipe 8.19

Inside the pc_debug() function in the first code block of the Solution, inside pc_debug() in the first code block of the Discussion, inside pc_debug() and in the if()/elseif() statement in the last code block of the Discussion: "defined(DEBUG)" NOW READS: "defined('DEBUG')

Anonymous    Feb 01, 2003
Printed
Page 234
Recipe 9.9

the second line from the bottom: "456" HAS BEEN REFORMATTED in bold, like the line "123" before it.

Anonymous    Jan 01, 2004
Printed
Page 239
the 23rd line from the top of the page

INSERT INTO zodiac VALUES (8,'Scorpio','Scorpion','Mars','water',20,24,11,21); NOW READS: INSERT INTO zodiac VALUES (8,'Scorpio','Scorpion','Mars','water',10,24,11,21);

Anonymous    Jan 01, 2004
Printed
Page 243
the line

ftruncate($fp,0) NOW READS: ftruncate($fh,0)

Anonymous    Apr 01, 2005
Printed
Page 244
Recipe 10.2

In the following code, the DBM handle was missing for dba_replace and dba_insert. The code at the bottom of page 244 NOW READS: $dbh = dba_open('fish.db','c','gdbm') or die($php_errormsg); // retrieve and change values if (dba_exists('flounder',$dbh)) { $flounder_count = dba_fetch('flounder',$dbh); $flounder_count++; dba_replace('flounder',$flounder_count, $dbh); print "Updated the flounder count."; } else { dba_insert('flounder',1, $dbh); print "Started the flounder count."; } The DBM handle was also missing in the code at the top of page 245; This code NOW READS: // what fish do we have? for ($key = dba_firstkey($dbh); $key !== false; $key = dba_nextkey($dbh)) { $value = dba_fetch($key, $dbh); => print "$key: $value "; } The DBM handle was also missing in the code at the bottom of page 246; This code NOW READS: // read in and unserialize the data if ($exists = dba_exists($_REQUEST['username'], $dbh)) { $serialized_data = dba_fetch($_REQUEST['username'], $dbh) or die($php_errormsg); $data = unserialize($serialized_data); } else { $data = array(); } The DBM handle was also missing for dba_replace and dba_insert, in the code at the top of page 247. This code NOW READS: // write data back to file if ($exists) { dba_replace($_REQUEST['username'],serialize($data), $dbh); } else { dba_insert($_REQUEST['username'],serialize($data), $dbh); }

Anonymous    Feb 01, 2003
Printed
Page 259
fourth non-code paragraph, second sentence

"if you call DB:quote()" NOW READS: "if you call DB::quote()"

Anonymous    Jan 01, 2004
Printed
Page 265
IN PRINT: Recipe 10.12, The seventh line from the bottom of the page

printf('<tr><td>%s: </td><td><input type="text" name="%s" value="%s">, NOW READS: printf('<tr><td>%s: </td><td><input type="text" name="%s" value="%s">',

Anonymous    Feb 01, 2003
Printed
Page 267
(actually on page 268) 10.13 Making Paginated Links...Solution code

Code lines at top of page 268: $sth = $dbh->query('SELECT * FROM zodiac ORDER by id'); $pager = new DB_Pager($sth, $offset, $per_page); $data = $pager->build(); // display each row on this page while ($v = $pager->fetchRow()) { print "$v->sign, $v->symbol ($v->id)<br>"; } NOW READ: $sth = $dbh->limitQuery('SELECT * FROM zodiac ORDER by id', $offset, $per_page); // display each row on this page while ($v = $sth->fetchRow()) { print "$v->sign, $v->symbol ($v->id)<br>"; } $data = DB_Pager::getData($offset, $per_page, $sth->numRows());

Anonymous    Jan 01, 2004
Printed
Page 326
code line before See Also

xslt_close() NOW READS xslt_free()

Anonymous    Feb 01, 2003
Printed
Page 326
Under "Solution"

The link - http://xmlrpc-epi.sourceforge.net/sample/utils/utils.php NOW READS: http://xmlrpc-epi.sourceforge.net/xmlrpc_php/index.php

Anonymous    Jan 01, 2004
Printed
Page 363
IN PRINT: code listing near the top of the page

mysql_connect('localhost',$_ENV['MYSQL_USER'],$_ENV['MYSQL_PASSWORD']); NOW READS: mysql_connect('localhost',$_SERVER['MYSQL_USER'],$_SERVER['MYSQL_PASSWORD']);

Anonymous    Feb 01, 2003
Printed
Page 365

$hash = md5($secret_word . $id); NOW READS: $hash = md5($secret_word . $cookie_value);

Anonymous    Jan 01, 2004
Printed
Page 381
code under "Solution"

$cmd = "echo $msg | HOME=$home_dir NOW READS: $cmd = "echo $message_body | HOME=$home_dir

Anonymous    Jan 01, 2004
Printed
Page 391
15.4 solution for postscript type1 fonts

ImageString($image, 'I love PHP.... NOW READS: ImagePSText($image, 'I love PHP...

Anonymous    Jan 01, 2004
Printed
Page 418
end of Example 16-1

Missing final } HAS BEEN ADDED.

Anonymous    Feb 01, 2003
Printed
Page 422
In Recipe 16.9, the 4th line from the bottom

$classname = "pc_MC_$locale.php"; NOW READS: $classname = "pc_MC_$locale";

Anonymous    Jan 01, 2004
Printed
Page 430
IN PRINT: 8th block of code

$headers = $mime->headers($headers); $body = $mime->get(); NOW READS: $body = $mime->get(); $headers = $mime->headers($headers);

Anonymous    Feb 01, 2003
Printed
Page 430
8th block of code

$headers = $mime->headers($headers); $body = $mime->get(); NOW READS: $body = $mime->get(); $headers = $mime->headers($headers);

Anonymous    Feb 01, 2006
Printed
Page 431
5th and 8th blocks of code

$headers = $mime->headers($headers); $body = $mime->get(); NOW READS: $body = $mime->get(); $headers = $mime->headers($headers);

Anonymous    Feb 01, 2006
Printed
Page 444
Solution: line 7 of code counting blank lines.

$info NOW READS: $e

Anonymous    Apr 01, 2005
Printed
Page 445
recipe 17.7, In paragraph 4,

"connect to an specific LDAP server" NOW READS: "connect to a specific LDAP server."

Anonymous    Jan 01, 2004
Printed
Page 449
last paragraph ("See Also")

gethostbyaddrl NOW READS: gethostbynamel()

Anonymous    Feb 01, 2003
Printed
Page 451
17.11 Solution

The book describes a beta version of Net_Whois. Between the time we wrote the chapter and Net_Whois 1.0, there were some backwards incompatible changes made to the API. Net_Whois::query() is no longer a static method Previously the Solution was: require 'Net/Whois.php'; $server = 'whois.networksolutions.com'; $query = 'example.org'; $data = Net_whois::query($server, $query); The Solution NOW READS: require 'Net/Whois.php'; $server = 'whois.networksolutions.com'; $query = 'example.org'; $whois = new Net_Whois; $data = $whois->query($server, $query); In discussion on page 452, the line "print Net_Whois::query('whois.internic.net', 'example.org');" NOW READS:: $whois = new Net_Whois; print $whois->query('example.org', 'whois.internic.net');

Anonymous    Apr 01, 2005
Printed
Page 482
The very last line of the page: "passes it two arguments: 12 and 56."

NOW READS: "passes it two arguments: 12; and 56."

Anonymous    Feb 01, 2003
Printed
Page 504
Recipe 19.9

Recipe 19.9 IS NOW titled "Processing All Files in a Directory Recursively." ("Recursively" was missing)

Anonymous    Jan 01, 2004
Printed
Page 590
index

the entry for median() which points to page 138 HAS BEEN CHANGED to mean()

Anonymous    Jan 01, 2004