Problem med klasse
Hej;Jeg har en fil, som jeg prøver lokalt at lege lidt med. Det er
fra en bog, hvor jeg bliver bedt om at oprette en klasse-fil,
hvorefter jeg skal bruge den klasse, og dens konstruktør.
Filen ser således ud (håber ikke det er for meget at læse
igennem):
<html>
<head>
<title>Listing 12.4 Using the date_pulldown Class</title>
</head>
<?php
class date_pulldown
var $name; <- LINJE 7
var $timestamp = -1;
var $months = array("Jan", "Feb", "Mar", "Maj", "Jun", "Jul",
"Aug", "Sep", "Okt", "Nov", "Dec");
var $yearstart = -1;
var $yearend = -1;
function date_pulldown($name)
{
$this->name = $name;
}
function setDate_global()
{
if (!$this->setDate_array($GLOBALS[$this->name]))
{
return $this->setDate_timestamp(time());
}
return true;
}
function setDate_timestamp($time)
{
$this->timestamp = $time;
return true;
}
function setDate_array($inputdate)
{
if (is_array($inputdate) && isset($inputdate['mon']) &&
isset($inputdate['mday']) && isset($inputdate['year']))
{
$this->timestamp = mktime(11, 59, 59, $inputdate['mon'],
$inputdate['mday'], $inputdate['year']);
return true;
}
return false;
}
function setYearStart($year)
{
$this->yearstart = $year;
}
function setYearEnd($year)
{
$this->yearend = $year;
}
function getYearStart ()
{
if ($this->yearstart < 0)
{
$nowarray = getdate(time());
$this->yearstart = $nowarray[year]-5;
}
return $this->yearstart;
}
function getYearEnd()
{
if ($this->yearend < 0)
{
$nowarray = getdate(time());
$this->yearend = $nowarray[year]+5;
}
return $this->yearend;
}
function output()
{
if ($this->timestamp < 0)
{
$this->setDate_global();
}
$datearray = getdate($this->timestamp);
$out = $this->day_select($this->name, $datearray);
$out .= $this->month_select($this->name, $datearray);
$out .= $this->year_select($this->name, $datearray);
return $out;
}
function day_select($fieldname, $datearray)
{
$out = "<select name=\"$fieldname"."[mday]\">\n";
for ($x=1; $x<=31; $x++)
{
$out .= "<option value=\"$x\"".($datearray['mday']==($x)
?" SELECTED":"").">"sprintf("%02d", $x ) ."\n";
}
$out .= "</select>\n";
return $out;
}
function month_select($fieldname, $datearray)
{
$out = "<select name=\"$fieldname"."[mon]\">\n;
for ($x = 1; $x <= 12; $x++)
{
$out .= "<option value=\"".($x)."\"".($datearray['mon']==($x) ?"
SELECTED":"")."> ".$this->months[$x-1]."\n";
}
$out .= "</select>\n";
return $out;
}
function year_select($fieldname, $datearray)
{
$out = "<select name=\"$fieldname"."[year]\">\n;
$start = $this->getYearStart();
$end = $this->getYearEnd();
for ($x = $start; $x <= $end; $x++)
{
$out .= "<option value=\"".($x)."\"".($datearray['year']==($x)
?" SELECTED":"").">$x\n";
}
$out .= "</select>\n";
return $out;
}
$date1 = new date_pulldown("fromdate");
$date2 = new date_pulldown("todate");
$date3 = new date_pulldown("foundingdate");
$date3->setYearStart(1972);
if (empty($foundingdate))
$date3->setDate_array(array('mday'=>26, 'mon'=>4,
'year'=>1984));
?>
<body>
<form>
From:<br><?php print $date1->output(); ?><p>
To:<br><?php print $date2->output(); ?><p>
Company founded:<br><?php print $date3->output(); ?><p>
<input type="submit" value="Submit Query">
</form></P>
</body>
</html>
Mit problem er, at når jeg kalder filen, før jeg følgende fejl:
Parse error: parse error, expecting `'{'' in D:\Apache
Group\Apache2\htdocs\listing12.4.php on line 7
Nogen der har en idé til hvad der kan være galt?