Page 1 of 1

Object of class Category could not be converted to string

Posted: Sat Dec 18, 2010 1:53 pm
by laanes
Hi everyone,

I get this error:

Catchable fatal error: Object of class Category could not be converted to string

The code:

Code: Select all

public static function list_all_cat_names() {
  	
  		$result_array = self::find_by_sql("SELECT name FROM ".self::$table_name);
  		return !empty($result_array) ? array_shift($result_array) : false;
  	
}


$categories = Category::find_all();

foreach ($categories as $cats):

echo $cats;

endforeach;
Where could be the problem?

Kind regards,
laanes

Re: Object of class Category could not be converted to strin

Posted: Sat Dec 18, 2010 2:08 pm
by Jonah Bron
You're trying to echo an object. Either that's not what you want to do, or you need to implement the __toString() magic method.

http://php.net/language.oop5.magic#lang ... c.tostring