PHP可捕获的致命错误:stdClass类的对象无法转换为字符串


PHP Catchable fatal error: Object of class stdClass could not be converted to string

$SourceID = $this->source_information->SourceID;
// the following fails 
if($results = $this->mysqli->query("SELECT .... R.Name = '$release_name' AND S.SourceID = $this->source_information->SourceID  AND S.ReleaseID = R.ReleaseID"))
// this will works  
if($results = $this->mysqli->query("SELECT .... R.Name = '$release_name' AND S.SourceID =  $SourceID  AND S.ReleaseID = R.ReleaseID"))

我有一大堆的代码$this->source_information->SourceID排序里面的东西,我真的不知道怎么重写它,告诉我我可以让这个工作。

编辑:

退出(var_dump ($ this -> source_information -> SourceID));

返回(string (2)"18")

感谢您提出准备好的语句。从现在开始,我将使用准备好的语句。

简单变量插值语法,即"$this->foo",最多只能解析一个嵌套对象。"$this->foo->bar"被解释为$this->foo加上字符串"->bar"。这就是为什么它抱怨source_information对象。如果你想嵌入更深的嵌套对象,使用复杂变量插值语法:

"... S.SourceID = {$this->source_information->SourceID}  AND ..."