array('category'):类 stdClass 的对象无法转换为字符串


array('category') : Object of class stdClass could not be converted to string

类 stdClass 的对象无法转换为字符串

public function get($id = null)
{
    $terms                  = array('id' => $id);
    $blog                   = $this->model->getBy($terms); 
    // $blog => (object) [id => 1, category_id => 3]
    $fix->id                = $blog->id;
    // $fix->category       = $this->getCategory($blog->category_id); // Not work
    $fix->cat_or_something = $this->getCategory($blog->category_id); // Work
    return $fix;
    // $fix => (object) [id => 1, cat_or_something => [name => Some Category]]
}

如果我用$fix->cat_or_something更改$fix->category,它将起作用。$fix->category有些奇怪.

问题出在代码中的其他地方。您很可能正在尝试在某处回显$fix>类别,并且由于它包含一个对象,因此会出现错误。

编辑 2:

再看了一会儿之后,我还是会继续我最初的答案。如果您在屏幕截图(http://d.pr/i/4Hn7)中查看代码的第 3 个版本,您将看到错误发生在print_r之后,因此在将其分配给 $fix-> 类别之后也是如此 - 所以这不是问题

错误发生在DB_active_rec.php中。这是我的版本(2.0)中的_where()方法。所以这意味着你正在尝试在某个地方使用$fix->类别......试着研究一下。

抱歉没有早点提供解决方案来解决导致我问题的挑战。

该问题是由两个相互关联的问题引起的:

  • 缓存问题
  • 库与当前 PHP 版本不兼容。这导致了正在使用的PHP版本与代码中使用的库之间的冲突。

幸运的是,通过重新安装PHP解决了这个问题,这涉及安装和集成更新的兼容版本。