I am replacing my old database layer by a new PDO based version.
However i have run into a problem:
When fetching objects using fetchObject
i ca
There doesn't seem to be a built-in solution. That part of the API doesn't look that good anyway. You could use a workaround:
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $stmt->fetch()) {
/* "Factory" */
$obj = new $row['class_name_column']('constructor', 'args');
unset($row['class_name_column']);
foreach ($row as $key => $value) {
$obj->$key = $value;
}
var_dump($obj);
}
I think it's perfectly clean to call an initializing-method on the returned instance right after the fetch.
It's a PHP bug reported as #62567
You may work around it by passing as a second argument any classname with a constructor