array('category'):无法将类stdClass的对象转换为字符串 [英] array('category') : Object of class stdClass could not be converted to string

查看:44
本文介绍了array('category'):无法将类stdClass的对象转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Object of class stdClass could not be converted to string

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->类别更改为 $ fix-> cat_or_something ,则它将起作用. $ fix->类别有点奇怪.

If I change $fix->category with $fix->cat_or_something, it will work. There's something strange about the $fix->category.

推荐答案

问题出在代码的其他地方.您最有可能尝试在某处回显$ fix-> category,由于它包含一个对象,因此会出现错误.

The problem is somewhere else in your code. You most probably are trying to echo $fix->category somewhere, and since it contains an object you get an error.

多看一点之后,我仍然会回答我的最初答案.如果您在屏幕快照中查看代码的第三版( http://d.pr/i/4Hn7),您会看到该错误在print_r之后发生,因此在将其分配给$ fix-> category之后也是如此-这样就不成问题了

After looking at it some more, I'm still going with my initial answer. If you look at the 3rd version of your code in your screenshot ( http://d.pr/i/4Hn7 ) you'll see that the error occurs after the print_r, so also after assigning it to $fix->category - so that's not the problem

该错误发生在 DB_active_rec.php 中.那是我的版本(2.0)中的_where()方法.因此,这意味着您正在尝试在某个地方的子句中使用$ fix-> category ...尝试调查.

The error occurs in the DB_active_rec.php. That's the _where() method in my version (2.0). So that would mean that you're trying to use $fix->category in a where clausule somewhere... Try looking into that.

这篇关于array('category'):无法将类stdClass的对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆