14. december 2006 - 16:06Der er
13 kommentarer og 1 løsning
Problemer med script der virkeri PHP4, men ikke i PHP5
Jeg har kørt med et script, der virker fint i PHP4, men har prøvet at køre det på PHP5, hvor det ikke virker.
Det giver ingen fejlmedddelser - al kode undlades bare at blive vist.
Det er et script, der bruger objektorienteret programmering. Jeg ved der er nogle ændringer i forhold til OOP fra PHP4 til PHP5, men jeg har ikke umiddelbart kunne finde noget, der kunne være problemet.
Er der nogle der har kendskab til evt. problemer, der kan opstå når man konverterer fra PHP4 til PHP5 i forhold til objektorienteret programmering?
Jeg har lidt svært ved at bringe konkret kode, da jeg formoder det er en overordnet fejl den er gal med.
kan det være at nogle af indstillingerne er anderledes i den nye installation af PHP? har du tjekket at error reporting er slået til og viser ALT så du kan få en ide om problemet? error_reporting(E_ALL);
class Calendar { /* Constructor for the Calendar class */ function Calendar() { }
/* Get the array of strings used to label the days of the week. This array contains seven elements, one for each day of the week. The first entry in this array represents Sunday. */ function getDayNames() { return $this->dayNames; }
/* Set the array of strings used to label the days of the week. This array must contain seven elements, one for each day of the week. The first entry in this array represents Sunday. */ function setDayNames($names) { $this->dayNames = $names; }
/* Get the array of strings used to label the months of the year. This array contains twelve elements, one for each month of the year. The first entry in this array represents January. */ function getMonthNames() { return $this->monthNames; }
/* Set the array of strings used to label the months of the year. This array must contain twelve elements, one for each month of the year. The first entry in this array represents January. */ function setMonthNames($names) { $this->monthNames = $names; }
/* Gets the start day of the week. This is the day that appears in the first column of the calendar. Sunday = 0. */ function getStartDay() { return $this->startDay; }
/* Sets the start day of the week. This is the day that appears in the first column of the calendar. Sunday = 0. */ function setStartDay($day) { $this->startDay = $day; }
/* Gets the start month of the year. This is the month that appears first in the year view. January = 1. */ function getStartMonth() { return $this->startMonth; }
/* Sets the start month of the year. This is the month that appears first in the year view. January = 1. */ function setStartMonth($month) { $this->startMonth = $month; }
/* Return the URL to link to in order to display a calendar for a given month/year. You must override this method if you want to activate the "forward" and "back" feature of the calendar.
Note: If you return an empty string from this function, no navigation link will be displayed. This is the default behaviour.
If the calendar is being displayed in "year" view, $month will be set to zero. */ function getCalendarLink($month, $year) { return ""; }
/* Return the URL to link to for a given date. You must override this method if you want to activate the date linking feature of the calendar.
Note: If you return an empty string from this function, no navigation link will be displayed. This is the default behaviour. */ function getDateLink($day, $month, $year) { return ""; } function getTextData($day, $month, $year) { return ""; }
/* Return the HTML for the current month */ function getCurrentMonthView() { $d = getdate(time()); return $this->getMonthView($d["mon"], $d["year"]); }
/* Return the HTML for the current year */ function getCurrentYearView() { $d = getdate(time()); return $this->getYearView($d["year"]); }
/* Return the HTML for a specified month */ function getMonthView($month, $year) { return $this->getMonthHTML($month, $year); }
/* Return the HTML for a specified year */ function getYearView($year) { return $this->getYearHTML($year); }
/* Calculate the number of days in a month, taking into account leap years. */ function getDaysInMonth($month, $year) { if ($month < 1 || $month > 12) { return 0; }
$d = $this->daysInMonth[$month - 1];
if ($month == 2) { // Check for leap year // Forget the 4000 rule, I doubt I'll be around then...
if ($year%4 == 0) { if ($year%100 == 0) { if ($year%400 == 0) { $d = 29; } } else { $d = 29; } } }
return $d; }
/* Generate the HTML for a given month */ function getMonthHTML($m, $y, $showYear = 1) { $s = "";
/* Generate the HTML for a given year */ function getYearHTML($year) { $s = ""; $prev = $this->getCalendarLink(0, $year - 1); $next = $this->getCalendarLink(0, $year + 1);
/* Adjust dates to allow months > 12 and < 0. Just adjust the years appropriately. e.g. Month 14 of the year 2001 is actually month 2 of year 2002. */ function adjustDate($month, $year) { $a = array(); $a[0] = $month; $a[1] = $year;
while ($a[0] > 12) { $a[0] -= 12; $a[1]++; }
while ($a[0] <= 0) { $a[0] += 12; $a[1]--; }
return $a; }
/* The start day of the week. This is the day that appears in the first column of the calendar. Sunday = 0. */ var $startDay = 0;
/* The start month of the year. This is the month that appears in the first slot of the calendar in the year view. January = 1. */ var $startMonth = 1;
/* The labels to display for the days of the week. The first entry in this array represents Sunday. */ var $dayNames = array("S", "M", "T", "O", "T", "F", "L");
/* The labels to display for the months of the year. The first entry in this array represents January. */ var $monthNames = array("Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December");
/* The number of days in each month. You're unlikely to want to change this... The first entry in this array represents January. */ var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
} class MyCalendar extends Calendar { var $plan; function MyCalendar(){ require_once("get_lib.php"); require_once("db.php"); $interviewerStatus=''; $sql_select_status='select status from brugere where loennr='.$_SESSION['loennr']; open_db(); $result_select_status=mysql_query($sql_select_status); while($row_select_status=mysql_fetch_array($result_select_status)) { $interviewerStatus=$row_select_status['status']; } open_db(); $sql = "select dato from booking where loennr=".$_SESSION['loennr'];
$result = mysql_query($sql); while($myrow = mysql_fetch_array($result)){ $tmpplan[substr($myrow['dato'],0,10)]++; } $this->$plan=$tmpplan; //Parse into local datastructure $text_lines =post_lib_get_plan($_SESSION['email']); $arr = split("\n", strip_tags($text_lines));
foreach($arr as $line){ $line_split = split("%",$line); $tmpplan[$line_split[0]]=$line_split[1]; }
$sql_all='select * from task where dato > now() and StartTime'.$interviewerStatus.' < now()'; $result_all=mysql_query($sql_all); while($row_all=mysql_fetch_array($result_all)) { $dato=$row_all['dato']; $fra=$row_all['fra']; $til=$row_all['til']; $maxworkers=$row_all['maxworkers']; $taskid=$row_all['id']; $sql_task ="SELECT * FROM userbooking where taskid=".$taskid." and loennr = ".$_SESSION['loennr']; $result_task = mysql_query($sql_task); $rows=mysql_num_rows($result_task); if ($rows > 0) { //do nothing } else { $my_sql_task="SELECT COUNT(*) FROM userbooking where taskid=".$taskid; $mytask = mysql_query($my_sql_task); while($myrow = mysql_fetch_array($mytask)) { $count=$myrow['COUNT(*)']; if ($maxworkers > $count) { $fra=substr($fra,11,5); $til=substr($til,11,5); $dato=substr($dato,0,10); $str =$fra." ".$til; $thisid = $taskid; $tmpplan["task".$dato] .= "Mulig vagt: <a href=\"booking_view.php?".SID."&taskid=$thisid\">$str</a><br>"; } else { //do nothing } } }
} close_db(); open_db(); $sql_select_bookings='select * from userbooking,task where userbooking.taskid=task.id and userbooking.loennr='.$_SESSION['loennr'].' and task.dato > now()'; $result_select_bookings=mysql_query($sql_select_bookings); while($row_select_bookings=mysql_fetch_array($result_select_bookings)) { $bookingfra=substr($row_select_bookings['fra'],11,5); $bookingtil=substr($row_select_bookings['til'],11,5); $bookingdato=substr($row_select_bookings['dato'],0,10); $bookingstr =$bookingfra." ".$bookingtil; $effektivarbejdstid=$row_select_bookings['effektivarbejdstid']; $tmpplan["task".$bookingdato] .= "Booket vagt: <font color=green>".$bookingstr."<br></font>Effektiv arbejdstid: <font color=green>".$effektivarbejdstid."</font><br></font>";
$this->$plan=$tmpplan; close_db(); } function getCalendarLink($month, $year) { $s = getenv('SCRIPT_NAME'); $s='booking_view.php'; return "$s?month=$month&year=$year"; } function leadingZero($int){ $s="$int"; if (strlen($s)==1){ return "0$s"; }else { return $s; } } function getDateLink($day, $month, $year) { //Man kan ikke udfylde timer frem i tiden. $d=getdate(time()); if($d["year"]<$year) return ""; if(($d["year"]==$year) and ($d["mon"]<$month)) return ""; if(($d["year"]==$year) and ($d["mon"]==$month) and ($d["mday"]<$day)) return ""; return "booking_view.php?".SID."&clickedDay=$day&month=$month&year=$year"; } function getTextData($day, $month, $year) { $d=getdate(time()); $month = $this->leadingZero($month); $day = $this->leadingZero($day); $tmpplan = $this->$plan; if ($tmpplan[$year.'-'.$month.'-'.$day]<>''){ for($i=0;$i<$tmpplan[$year.'-'.$month.'-'.$day];$i++){ $textData.="<img src=\"gfx/timeseddel.gif\" alt=timeseddel>"; } } if ($tmpplan['task'.$year.'-'.$month.'-'.$day]<>''){ $textData.=$tmpplan['task'.$year.'-'.$month.'-'.$day]; } $tmpplan[$year.'-'.$month.'-'.$day]; if($d["year"]>$year) return $textData; if(($d["year"]==$year) and ($d["mon"]>$month)) return $textData; if(($d["year"]==$year) and ($d["mon"]==$month) and ($d["mday"]>$day)) return $textData; $month = $this->leadingZero($month); $day = $this->leadingZero($day); $textData.=$tmp_plan["$year $month $day"]; return $textData; } } ?>
og det skal lige siges at med det kode du har givet mig her så virker det efter den '}' er tilføjet. Det ser lidt underligt ud, men der er da output og jeg bruger php 5.2.0.
Det var ikke for at virke kort for hovedet i min sidste kommentar, jeg havde bare noget andet jeg skulle nå, så det blev lidt kortfattet. en af de ting du skal have gjort er at sætte public og private på variabler og funktioner og variablerne skal defineres. Der er muligvis mere, men jeg har ikke lige så meget styr på forskellen mellem OOP i php4 og php5. Har nemlig aldrig brugt det før php5
Tak for de gode svar. Jeg undlod at omskrive koden, da jeg ikke var sikker på de sideeffects det evt. kunne give, så vi satte istedet serveren op, så den kan køre både php4 og php5. Hvis du poster noget sw_red_6 skal du få nogle point.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.