无法将对象转换为字符串? [英] Object could not be converted to string?
本文介绍了无法将对象转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么会出现此错误:
可捕获的致命错误:类别为Card的对象无法转换为 第79行的/f5/debate/public/Card.php中的字符串
Catchable fatal error: Object of class Card could not be converted to string in /f5/debate/public/Card.php on line 79
这是代码:
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
的一部分)
(Line 79 is the $query
and the function is part of class Card
)
Card
的所有声明:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
将第79行更改为此:
After changing line 79 to this:
$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中输入字符串
Catchable fatal error: Object of class Author could not be converted to string in /f5/debate/public/Card.php on line 79
推荐答案
查看全文