ZF-4486: PDOStatement is of type Traversable, Zend_Db_Statement should be an Iterator


PDOStatement has type Traversable. This is a php-internal type. To my surprise Zend_Db_Statement doesn't expose this interface. I expect at least Zend_Db_Statement_Pdo to be iterative. Iterator extends Traversable and this interface can be used in userland code. Implementing the Iterator interface for Zend_Db_Statement would solve this discrepancy. We can throw an NotImplementedException for rewind().


Perhaps we could use IteratorAggregate.

The getIterator() method could then return the PDOStatement, as return $this->_stmt

Something like this works :

class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
   / ...
    public function getIterator()
        return new IteratorIterator($this->_stmt);

But I don't know if that is THE solution.

r13420 adds the improvement