yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Fix PDO::FETCH_CLASS without PDO::FETCH_PROPS_LATE. #75

Closed vlaaadislav closed 4 years ago

vlaaadislav commented 4 years ago

PDO::FETCH_CLASS: returns a new instance of the requested class, mapping the columns of the result set to named properties in the class, and calling the constructor afterwards, unless PDO::FETCH_PROPS_LATE is also given.

As I understood, constructor should be called after properties mapping.

yajra commented 4 years ago

@vlaaadislav thanks for this. can you please provide some snippets on how to use this PR?

vlaaadislav commented 4 years ago

PHP:

class Person
{
    public function __construct()
    {
        dd($this);
    }
}

$pdo = DB::getPdo();
$stmt = $pdo->prepare("SELECT * FROM people");
$result = $stmt->execute();
$stmt->fetchAll(PDO::FETCH_CLASS, 'Person');

What I expect dump inside constructor will print:

Person{
  +"id": "1"
  +"name": "One"
}

But now it works as $stmt->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person'): Person{}

yajra commented 4 years ago

Thanks! will review / test this as soon as I can. A good ref that gives me a better understanding of this issue.