yajra / pdo-via-oci8

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

setFetchMode(PDO::FETCH_CLASS, 'Classtype') and fetchAll() returns array<stdClass> #120

Open haexed opened 2 years ago

haexed commented 2 years ago

Summary

When using setFetchMode(\PDO::FETCH_CLASS, 'Classtype') and fetchAll(), the returned type is array<\stdClass> because fetchAll() will ignore the previously set fetchClassName.

The expected behaviour is that fetchAll() returns array<Classtype> as set previously with setFetchMode().

Test case

class Classtype
{
    public int $id;
}

$sql = "SELECT 1 as id FROM dual";

/*
Working test, $result is array<Classtype>
*/
$stmt = $pdo->query($sql);
$result = $stmt->fetchAll(\PDO::FETCH_CLASS, 'Classtype');
var_dump($result);
/*
array(1) {
    [0]=>
    object(Classtype)#5 (1) {
        ["id"]=>
        int(1)
    }
}
*/

/*
Failing test, $result is array<stdClass>
*/
$stmt = $pdo->query($sql);
$stmt->setFetchMode(\PDO::FETCH_CLASS, 'Classtype');
$result = $stmt->fetchAll();
var_dump($result);
/*
array(1) {
    [0]=>
    object(stdClass)#6 (1) {
        ["id"]=>
        string(1) "1"
    }
}
*/

System details