The Note You're Voting On
phpnet at nicecupofteaandasitdown dot com ¶ 20 years ago
You should be prepared for your iterator's current method to be called before its next method is ever called. This certainly happens in a foreach loop. If your means of finding the next item is expensive you might want to use something like this
private $item;
function next() {
$this->item = &$this->getNextItem();
return $this->item;
}
public function current() {
if(!isset($this->item)) $this->next();
return $this->item;
}