private $master_id;
private $master;
- private $stepped;
+ private $over = array();
+ private $stepped = array();
private $current_elts = array();
private $callback_res = array();
foreach ($this->ids as $id) {
$this->stepped[$id] = false;
+ $this->over[$id] = false;
$this->current_elts[$id] = null;
$this->callback_res[$id] = null;
}
return;
}
+ // Don't do anything if the iterator is at its end
+ if ($this->over[$id]) {
+ $this->stepped[$id] = true;
+ return;
+ }
+
$it = $this->iterators[$id];
$nxt = $it->next();
+ $this->stepped[$id] = true;
+ if ($nxt === null) {
+ $this->over[$id] = true;
+ $this->current_elts[$id] = null;
+ $this->callback_res[$id] = null;
+ return;
+ }
$res = call_user_func($this->callbacks[$id], $nxt);
$this->current_elts[$id] = $nxt;
$this->callback_res[$id] = $res;
- $this->stepped[$id] = true;
}
private function stepAll()
public function next()
{
$this->stepAll();
- if ($this->current_elts[$this->master_id] == null) {
+ if ($this->current_elts[$this->master_id] === null) {
return null;
}