我已经查看了这个代码一个多小时,对我来说它看起来不错。但是,当我使用 insertSubmit() 函数时,描述变量正在失去作用域。该变量是在构造过程中设置的,但不是在我使用 insertSubmit() 时设置的。我在这里错过了什么吗?
<?php session_start();
class SubmitNew {
var $title = "";
var $category = "";
var $summary = "";
var $description = "";
var $username = "";
var $timestamp = "";
var $errors = "";
var $errorStr = "";
var $link = "";
var $db = "";
public function __construct() {
$this->setVariables();
$this->errors = 0;
$this->p_id = 1;
}
public function setVariables() {
$this->title = "1";
$this->category = "2";
$this->summary = "3";
$this->description = "4";
echo $this->description;
$this->timestamp = mktime(date("G"), date("i"),
date("s"), date("m") , date("d"), date("Y"));
}
public function errorBlank() {
if($this->title == null) {
$this->errorStr = $this->errorStr."blanktitle";
$this->errors++;
} if($this->summary == null) {
$this->erroStr = $this->errorStr."blanksummary";
$this->errors++;
} if($this->description = null) {
$this->erroStr = $this->errorStr."blankdescription";
$this->errors++;
}
}
public function errorAll() {
if($this->errors == 0) {
return "success";
} else {
return $this->errorStr;
}
}
public function insertSubmit() {
echo $this->description;
}
}