对象无法转换为字符串?
2022-08-30 22:12:31
为什么我会收到此错误:
可捕获的致命错误:类 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')";
我现在得到这个错误:
可捕获的致命错误:类作者的对象无法转换为 /f5/debate/public/Card.php 第 79 行中的字符串