public function offsetGet($offset)
{
if (isset($this->cache[$offset])) {
// found in cache
return clone $this->cache[$offset];
} elseif ($this->total !== null) {
// cache complete and not found in cache
return null;
}
// not in cache and cache not complete, we have to loop to find it
$i = 0;
foreach ($this as $occurrence) {
if ($i == $offset) {
return $occurrence;
}
$i++;
if ($i > $offset) {
break;
}
}
return null;
}