【发布时间】:2010-07-08 05:37:33
【问题描述】:
为什么会出现这个错误:
可捕获的致命错误:Card 类的对象无法转换为 第 79 行 /f5/debate/public/Card.php 中的字符串
代码如下:
public function insert()
{
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards
VALUES('$this->$type','$this->$tag','$this->$author->$last','$this->$author->$first',
'$this->$author->$qualifications','$this->$date->$year','$this->$date->$month',
'$this->$date->$day','$this->$title', '$this->$source', '$this->$text')";
$mysql->execute($query);
}
(第 79 行是 $query,该函数是 Card 类的一部分)
Card的所有声明:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
将第 79 行更改为:
$query = "INSERT INTO cards
VALUES('$this->type','$this->tag','$this->author->last','$this->author->first',
'$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day',
'$this->title', '$this->source', '$this->text')";
我现在收到此错误:
可捕获的致命错误:无法转换 Author 类的对象 在第 79 行的 /f5/debate/public/Card.php 中字符串
【问题讨论】:
-
那是因为
$this-$author->qualifications
标签: php