Errata

PHP Hacks

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 62
within function drop ( sid )

The following line has an error:

divobj.style.top = aobj.offsetBottom+10;

when this line is commented out, the code works without issue.

Anonymous  Nov 04, 2008 
Printed Page 81-92
call to set text

I am a big fan of PHP hacks. However I am having trouble getting the calendar to work.
The problem is that the call to setCalendarText does not seem to be inserting the
text into the $days. Everything else is fine.

This is the class declaration:

class Day
{
function Day ($inmonth, $month, $day, $year)
{
$this->{'month'} = $month;
$this->{'day'} = $day;
$this->{'year'} = $year;
$this->{'month'} = $month;
$this->{'inmonth'} = $inmonth;
$this->{'text'} = '';
}
function get_day() { return $this->{'day'};}
function get_month() { return $this->{'month'};}
function get_year() { return $this->{'year'};}
function get_inmonth() { return $this->{'inmonth'};}
function get_text() { return $this->{'text'};}
function set_text($text){ $this->{'text'}=$text; }
}

Here is the setCalendarText function:

function setCalendarText( $days, $m, $d, $y, $text )
{
foreach( $days as $day)
{
if( $day->get_day() == $d && $day->get_month() == $m && $day->get_year() == $y )
$day->set_text($text);

}
}

Here is the page call:

<div class"calendar_content">
<?php echo ( $d->get_text() ); ?>
</div>

Echoing $this->{'text'} in the function set_text shows the text but it does not get
inserted into the $days and therefore does not appear on the page.

Can you offer any insights?

Anonymous   
Printed Page 88
Some place in code

Hack #25
The last day of previous month is always wrong.

Anonymous   
Printed Page 88
function setCalendarText

I have tried everything and cannot get the text to show in the calendar. And where is
the function number used? I see no call for it.

Anonymous   
Printed Page 90
3rd line from bottom

Previous month ends a day early.
Creating days for previous month needs to subtract 1 from the day value.

It appears that the previous errata for this is incorrect. They state that you need to subtract 1
from ($day - $d) but you need to add 1.
Was (in book): $days[] = new Day(0, $lastmonth + 1, $dimlm - ($day - $d), $lastyear);

Should be:
$days[] = new Day(0, $lastmonth + 1, $dimlm - ($day - $d) + 1, $lastyear);

Anonymous   
Printed Page 90
In 9780596101398.confirmed on website

In the confirmed errata, you have a correction stating:
---------------------------------------------------------
Page 90:
Previous month ends a day early.
Creating days for previous month needs to subtract 1 from the day value.
<is>
$days []= new Day(0,$lastmonth+1,$dimlm - ($day -$d), $lastyear);
<should be>
$days []= new Day(0,$lastmonth+1,$dimlm - ($day - $d) - 1, $lastyear);
---------------------------------------------------------

In actual fact, you need to add one, not subtract
$days []= new Day(0,$lastmonth+1,$dimlm - ($day - $d) + 1, $lastyear);

Anonymous   
Printed Page 91
16th & 17th line of code

while running this script in a php 5 environmen i encountered the following warnings:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would
like to pass it by reference, modify the declaration of setCalendarText(). If you would like to
enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI
file. However, future versions may not support this any longer. in C:webrootcityofwpbcalcal.php
on line 127

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would
like to pass it by reference, modify the declaration of setCalendarText(). If you would like to
enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI
file. However, future versions may not support this any longer. in C:webrootcityofwpbcalcal.php
on line 128

The deprecated problem should be taken care of.

Anonymous   
Printed Page 91
4th pocket of code

if ($_GET['month'] ) $month = $_GET['month'];

This section of code won't work when the current month is December, going forward a month. January is represented in 0 in your code. As it is 0 the if statement is evaluated to false, so the line of code will never be executed and January will not be set as the month. It will always be set to the current month that your server thinks that it is.

Anonymous  Nov 19, 2008 
Printed Page 91
Chapter 3: Create an Interactive Calendar

Hi,

wrong previous/next month:

Actually the calender starts with June 2013.

# When clicking back: the change from Feb 2013 to Jan 2013 does not work --> instead of Jan 2013 the calender goes to June 2013 again.

# When clicking forward: the change from Dec 2013 to Jan 2014 does not work --> instead of Jan 2013 the calender goes to June 2014.

Best regards,
Christian.

Anonymous  Jun 24, 2013 
Printed Page 151
4th line

require_once( "DB.php" );

This occurs on several pages but there does not appear to be anywhere where the content of that file is listed.

Calum MacLeod  May 28, 2009 
Other Digital Version 155
just replying to above post RE: Generate CRUD Database Code Hack #37:

In
http://examples.oreilly.com/9780596101398/phphacks.tgz

last modified 12-Aug-2009 09:09

the gencrud example works perfectly.

I used genselect/gen.php with gencrud/schema.php to get the sql to load my database.

line 49 of genselect/gen.php is interesting in that how much you indent affects the output and byte count. You might have to play with that a bit, indent less. My first pass generated a | (pipe) character before each field.

be sure you have the correct
path to pear/PEAR/
database name
and $dsn in dbwrap.php

Carpintonto  Feb 04, 2010 
Other Digital Version 155
correcting my previous submission

I used gensql/gen.php with gencrud/schema.php to get the sql to load my database.

line 47 of gensql/gen.php

<?php echo( $first ? "" : "," ) ?>

is interesting in that how much you indent affects the output and byte count. You might have to play with that a bit, indent less. My first pass generated a | (pipe) character before each field.

Carpintonto  Feb 07, 2010 
Printed Page 157
various, including six lines up fro the bottom of page 157; but others as well

RE: Generate CRUD Database Code Hack #37:

I am getting null values for all instances where "<?php echo( $pk ); ?>" is intended to place the
name of the primary key field into the output from gen.php script.

I have gone in circles attempting to reslove the issue, to no avail. The confusion is related to the
issue previously reported in online ERRATA pertaining to page 158 where a literal "id" was used to
reference what ought to be another instance of the "$pk" value.

However, even with that information, I am not yet able to resolve the problem. I believe the solution
may require iterating through the current table[field] array to locate an instance of A PRIMARY-KEY-
FIELD NAME. Thus far, a solution has escaped me. And I don't know whether gen.php will work with
tables that have multiple primary keys defined...

Furthermore, the problem appears to manifest itself elsewhere also, as "gen.php" is placing a "$this-
>" null value at the end of the all the locations where the "$updfields" array is being inserted.

This is probably a simple fix for the author, who will readily recognize where the "ID" and "PK"
references need to be distinguished. Meanwhilie, if you have a solution, I would like to hear about
it ASAP.

Anonymous   
Printed Page 157-60
various as indicated below

Follow up on Hack#37 Issues:

I believe I now have gen.php script working; please review the following feedback:

A. Page 157, 11 lines from the bottom of the page,
It appears the line
$this->id = null;
Should read
$this-><?php echo( $pk ); ?> = null;

B. Instructions should include that line on page 156:
$field['pk'] = ( $attribs['PRIMARY-KEY'] == "true" ) ? 1 : 0;
May need to be modified to match external XML attribute specifications, e.g.:
$field['pk'] = ( $attribs['PRIMARY_KEY'] == "yes" ) ? 1 : 0;

C. Some "best practices" discussion could be included regarding the prerequisite
that every table must contain at least one primary key field. If this is not the case,
then the program needs to handle references where no primary key exists.

D. To my knowledge, sql "views" do not signify primary keys, therefore, gen.php
will not correctly process "sql views" when they are included within the XML schema.

E. Oddly, using Hack #39 to generate XML will not work with Hack #37 because the XML
attributes do not include the "primary key" indicators.
I used another export utility to retrieve the XML schema:
http://www.webcheatsheet.com/php/export_database_schema_xml.php

Anonymous   
Printed Page 157
various, including six lines up fro the bottom of page 157; but others as well

RE: Generate CRUD Database Code Hack #37:

I really like the book; but am getting null values for all instances where "<?php echo( $pk ); ?>" is intended to place the name of the primary key field into the output from gen.php script.

I have gone in circles attempting to reslove the issue; to no avail. The confusion is related to the issue previously reported in online ERRATA pertaining to page 158 where a literal "id" was used to reference what ought to be another instance of the "$pk" value.

However, even with that information, I am not yet able to resolve the problem. I believe the solution may require iterating through the current table[field] array to locate an instance of A PRIMARY-KEY-FIELD NAME. Thus far, a solution has escaped me. And I don't know whether gen.php will work with tables that have multiple primary keys defined...

Furthermore, the problem appears to manifest itself elsewhere also, as "gen.php" is placing a "$this->" null value at the end of the all the locations where the "$updfields" array is being inserted.

This is probably a simple fix for the author, who will readily recognize where the "ID" and "PK" references need to be distinguished. I'll keep trying....

Meanwhilie, if you have a solution, I would like to hear about it ASAP. Thank you.


Anonymous  Jun 04, 2008 
Printed Page 268
Six lines from bottom of page

script says
"WHERE orderid = $orderid";

but it should be

"WHERE orderid = '$orderid'";

Alan Berman  Apr 26, 2010 
Printed Page 406
$images array at top of code sample plus updates to version 2

The values for latitude and longitude were transposed. They should be this:

$images = array(
array( 'lat' => 37.5029, 'lon' => -121.9033, 'img' => "mp0.jpg" ),
array( 'lat' => 37.5050, 'lon' => -121.8949, 'img' => "mp1.jpg" ),
array( 'lat' => 37.5060, 'lon' => -121.8889, 'img' => "mp2.jpg" ),
array( 'lat' => 37.5076, 'lon' => -121.8855, 'img' => "mp3.jpg" ),
array( 'lat' => 37.5115, 'lon' => -121.8835, 'img' => "mp4.jpg" ),
array( 'lat' => 37.5120, 'lon' => -121.8805, 'img' => "mp5.jpg" )
);

Updates to version 2 api:
line 15:

<script src="http://maps.google.com/maps?file=api&v=2&key=<mapkey>" type="text/javascript"></script>


lines 37 - 39:

var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.5088, -121.8858), 13, G_SATELLITE_MAP);
map.addControl(new GSmallMapControl());

line 53:

markers[i] = new GMarker( new GLatLng( mp_images[i].lat, mp_images[i].lon ), icon );

Carpintonto  Jan 17, 2010