for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace itertools;
use Iterator;
use PDO;
use PDOStatement;
class PDOStatementIterator implements Iterator
{
protected $stmtFactory;
protected $fetchStyle;
protected $currentValue;
protected $currentKey;
public function __construct($stmt, $fetchStyle = PDO::FETCH_BOTH)
if(is_callable($stmt)) {
$this->stmtFactory = $stmt;
} else {
$this->stmtFactory = function() use ($stmt) { return $stmt; };
}
$this->fetchStyle = $fetchStyle;
$this->stmt = $stmt;
stmt
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
public function rewind()
$this->stmt = call_user_func($this->stmtFactory);
$this->next();
$this->currentKey = 0;
public function valid()
return false !== $this->currentValue;
public function current()
return $this->currentValue;
public function key()
return $this->currentKey;
public function next()
$this->currentKey += 1;
$this->currentValue = $this->stmt->fetch($this->fetchStyle);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: