tags:

views:

48

answers:

3

I have a really odd error:

[04-Jun-2010 15:55:32] PHP Catchable fatal error: Object of class Type could not be converted to string in /home/prettykl/public_html/2010/includes/functions.php on line 140

This is the code and line 140 is the $sql line.

if (!empty($type)) {

    $sql = "SELECT * FROM `types` WHERE `type` = '$type'";
    $dbi = new db();    
    $result = $dbi->query($sql);
    $row = mysql_fetch_row($result);

    $dbi->closeLink();

    $where_array[] = "`typeID` = '".$row->typeID."'";
    $where_array[] = "`typeID2` = '".$row->typeID."'";
}

I have 5 or 6 classes and I've never encountered this problem before. The function has no reference to the classes, any ideas??

Thanks,

Stefan

+1  A: 

$type is an object of the class Type. You probably want to query a property of that object?

Pekka
In addition use print_r($type) to find out what it actually is
Manos Dilaverakis
$type must be an instance of Type, as the error states.
nuqqsa
+1  A: 

The error means that $type is actually an object (of class Type), so either the $type variable doesn't contain what you expect, or you actually want to get a member of the object instead, so $type->getSomeString(), etc.

Rich Adams
+1  A: 

This error happens when you try to convert an object to string and the object doesn't implement the __toString() method. PHP can't handle that conversion. For instance:

$s = new stdClass();
echo $s;

Catchable fatal error: Object of class stdClass could not be converted to 
string in php shell code on line 1

Note that you are outputting $type inside the query, as if it was a string.

nuqqsa
+1 for extensive explanation.
Pekka