2010-06-04 99 views
1

我有一個非常奇怪的錯誤:在PHP中可捕獲的錯誤?

[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

這是代碼和行140是$ SQL線。

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."'"; 
} 

我有5或6班,我從來沒有遇到過這個問題。 函數沒有參考類,任何想法?

謝謝,

的Stefan

回答

1

$type是類Type的對象。您可能想要查詢該對象的屬性?

+0

另外使用print_r($ type)來查明它實際是什麼 – 2010-06-04 15:08:33

+0

$ type必須是Type的一個實例,如錯誤狀態。 – nuqqsa 2010-06-04 15:14:17

1

錯誤表示$type實際上是一個對象(類Type),因此$type變量不包含您期望的內容,或者您​​實際上想要獲取對象的成員,因此$type->getSomeString()等等

1

當您嘗試將對象轉換爲字符串並且該對象不執行__toString()方法時,會發生此錯誤。 PHP無法處理該轉換。例如:

$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 

請注意,您在輸出$type查詢裏面,就好像它是一個字符串。

+0

+1進行廣泛的解釋。 – 2010-06-04 15:42:11