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>

按月统计

  1. 2021-12 (357)
  2. 2022-02 (10)
  3. 2022-03 (10)
  4. 2022-05 (1)
  5. 2023-06 (108)
  6. 2023-07 (44)
  7. 2023-08 (3)
  8. 2023-09 (8)
RangeTime:0.012672s
RangeMem:208.71 KB
返回顶部 留言