Is there a way to count the number of variables in an object?
I have a object that is created dynamically, and I want to add each of the properties to a query to update these properties into the database. The variable $oProperties is an object:
public function update_model ($id, $oProperties)
{
$SQL = "UPDATE `table` SET ";
$count = 0;
foreach($oProperties as $property=>$value)
{
$count++;
$SQL .= strtolower($property)." = '".$value."'";
if($count !== $oProperties::count()) {$SQL .= ", ";}
}
$SQL .= " WHERE id='".$id."';";
}
I need to know the amount of properties in the object to know when to stop adding the comma to the query.
$oPropertiesobject?$SQL = substr($SQL,-1)