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

Exception or error:

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]]

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

How to solve:

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.

Edit 2:

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 ( ) 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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *