I have a class that uses magic methods to store properties. Here is a simplified example:
class Foo {
protected $props;
public function __construct
The default behavior of PDO is to set the properties before invoking the constructor. Include PDO::FETCH_PROPS_LATE
in the bitmask when you set the fetch mode to set the properties after invoking the constructor, which will cause the __set
magic method to be called on undefined properties.
$st->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Foo');
Alternatively, create an instance and fetch into it (i.e. set fetch mode to PDO::FETCH_INTO
).