I have a class represents a table in database I want to fill the table into array of objectsas following:
$subCat = array();
$count=0;
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$subCatName = $line["sub_cat_name"];
$subCatShortDescription = $line["short_description"];
$subCatLongDescription = $line["long_description"];
$subCat = new SubCat($countryId, $catName, $subCatShortDescription, $subCatLongDescription);
$subCat[$count++] = $subCat;
}
I get the following error:
Fatal error: Cannot use object of type SubCat as array in C:\AppServ\www\MyWebSite\classes\SubCat.php on line 34
Thanks
$subcatas an empty array and then you create it as some sort of object withnew Subcat. Then, you try to use is as an array again. That's what PHP is complaining about.