diff --git a/lib/Predis/Collection/Iterator/CursorBasedIterator.php b/lib/Predis/Collection/Iterator/CursorBasedIterator.php index 3368bd77..32632443 100644 --- a/lib/Predis/Collection/Iterator/CursorBasedIterator.php +++ b/lib/Predis/Collection/Iterator/CursorBasedIterator.php @@ -165,16 +165,18 @@ abstract class CursorBasedIterator implements Iterator */ public function next() { - if (!$this->elements && $this->fetchmore) { - $this->fetch(); - } + tryFetch: { + if (!$this->elements && $this->fetchmore) { + $this->fetch(); + } - if ($this->elements) { - $this->extractNext(); - } elseif ($this->cursor) { - $this->next(); - } else { - $this->valid = false; + if ($this->elements) { + $this->extractNext(); + } elseif ($this->cursor) { + goto tryFetch; + } else { + $this->valid = false; + } } }