<?php
use PHPSnippets\Db\Entity\Test;
use Doctrine\ORM\Query;
$qb = $entityManager->createQueryBuilder();
$qb->select('t')
->from(Test::CLASS, 't')
->where('t.id < :id');
$iterator = $qb->getQuery()->iterate(['id' => 4]);
// hydration only happens row by row, making
// iterator less memory intensive
foreach ($iterator as $entity) {
echo $entity[0]->id . ', ' . $entity[0]->name . PHP_EOL;
}