DBAL-196: The function fetchAll(PDO::FETCH_ALL, 'MyClass') doesn't create object of MyClass #1367

doctrinebot opened this Issue Jan 6, 2012 · 2 comments

1 participant


Jira issue originally created by user noodha:

The code below doesn't create objects of MyClass when it has to.
Instead it create StdClass objects

$stmt = $db->prepare($sql);

$results = $stmt->fetchAll(

The problem comes from the file Doctrine/DBAL/Statement.php

     * Returns an array containing all of the result set rows.
     * @param integer $fetchStyle
     * @param integer $columnIndex
     * @return array An array containing all of the remaining rows in the result set.
    public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
    if ($columnIndex != 0) {
            return $this->_stmt->fetchAll($fetchStyle, $columnIndex);
        return $this->_stmt->fetchAll($fetchStyle);

The line

if ($columnIndex != 0) {

must be replace by

if ($columnIndex !== 0) {

because the parameter $columnIndex is not always an integer and could be a name of a class : see the example n°4 in php doc http://www.php.net/manual/en/pdostatement.fetchall.php


Comment created by @beberlei:

Fixed and merged into 2.2


Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added the Bug label Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.2 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment