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行是$查询,功能是类卡的一部分) 卡的所有声明: 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')"; 
 我现在得到这个错误: 阅读约 string parsing,您必须用括号{}括起变量: $query = "INSERT INTO cards VALUES('$this->type','{$this->author->last}'," 
 无论何时要访问字符串中属性的多维数组或属性,都必须使用{}包含此访问.否则,PHP将仅解析变量,直到第一个[i]或 – >属性. 所以使用“$this-> author-> last”而不是“{$this-> author-> last}”,PHP只会解析和评估$this->作者,它将错误提供给作者是一个对象. (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
