脚本宝典收集整理的这篇文章主要介绍了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); }
卡的所有声明:
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')";
我现在得到这个错误:
$query = "INSERT INTO cards VALUES('$this->type','{$this->author->last}',"
无论何时要访问字符串中属性的多维数组或属性,都必须使用{}包含此访问.否则,PHP将仅解析变量,直到第一个[i]或 – >属性.
所以使用“$this-> author-> last”而不是“{$this-> author-> last}”,PHP只会解析和评估$this->作者,它将错误提供给作者是一个对象.
以上是脚本宝典为你收集整理的php – 对象无法转换为字符串?全部内容,希望文章能够帮你解决php – 对象无法转换为字符串?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。