gpt4 book ai didi

php - 解析错误 : syntax error, 意外 '->' (T_OBJECT_OPERATOR)

转载 作者:可可西里 更新时间:2023-10-31 23:52:25 25 4
gpt4 key购买 nike

<分区>

我感觉这可能是一个简单的语法错误,我只是没有看到,因为我仔细查看了代码,无法弄清楚为什么会出现上述错误。我正在处理的代码是 SAMS 书籍中关于构建日历类的教程。作为记录,我正在运行 PHP 5.4.7。下面的代码属于我将在下面显示的包含。

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]\">";
$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;
}
}
?>

以及显示(包括)页面的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example 12.4 - Using the date_pulldown Class</title>
</head>
<?php
include("date_pulldown.php");
$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(); ?><br /><br />
To:<br />
<?php print $date2->output(); ?><br /><br />
Company founded:<br />
<?php print $date3->output(); ?><br /><br />
<input type="submit" />
</form>
</body>
</html>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com