php 之 Object of class stdClass could not be conver

<p>今天用Php进行输出时遇到了如下错误:</p><p>Catchable fatal error: Object of class stdClass could not be converted to string in ……\***.php on line 10</p><p>具体错误是语句:echo $result;</p><p>从错误说明中可知$result是class stdClass类型,我们用var_dump()函数进行了输出,此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。 语句为</p><p>var_dump($result);</p><p>显示结果为:</p><p>object(stdClass)#2 (1) { [&quot;return&quot;]=&gt; string(46) &quot;Hello, My Friend!&quot;}</p><p>很明显,我们想要输出的结果就是&quot;Hello,My Friend!&quot;,代表的就是这个类对象中return变量的值,因此,我们可用如下语句输出我们想要的值:</p><p>echo $result-&gt;return;</p><p>替代原来的echo $result;</p>
RangeTime:0.007345s
RangeMem:204.61 KB
返回顶部 留言