As stated here:
http://us.php.net/manual/en/language.oop5.iterations.php
Normally, we iterate over an object by doing:
foreach($class as $key => $value)
{
print "$key => $value
";
}
But I’m not being able to do this with a stdClass object returned by fetch_all method using FETCH::OBJ option.
I get a:
Catchable fatal error: Object of class stdClass could not be converted to string
And I don’t understand what I’m doing wrong…
What could it be?
Thanks in advance,
Márcio
Update:
$objRecord = $this->_daoh->listar();
The method that returns the object:
public function listar()
{
try
{
$query_str='SELECT * FROM table';
$stmt = $this->_dbh->query($query_str);
$records = $stmt->fetchAll(PDO::FETCH_OBJ);
return $records;
}
catch (PDOException $ex)
{
echo "Erro: " . $ex->getMessage();
}
}
The try:
foreach ($objRecord as $property => $property_value)
{
print "$property => $property_value\
";
}
M. x_x