PHP Hacks by Jack D. Herrington The unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification This page was updated July 28, 2008. UNCONFIRMED errors and comments from readers: [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:
get_text() ); ?>
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? {88} Some place in code; Hack #25 The last day of previous month is always wrong. [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. (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); {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. $days []= new Day(0,$lastmonth+1,$dimlm - ($day -$d), $lastyear); $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); [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:\webroot\cityofwpb\cal\cal.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:\webroot\cityofwpb\cal\cal.php on line 128 The deprecated problem should be taken care of. [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 "" 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. [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-> = 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