offsetGet($index) 會回傳儲存在快取中 $index 位置的值。在您迭代過這些項目之前,快取是空的,而且索引將不存在。
迭代
<?php
$cache = new \CachingIterator(
new \ArrayIterator(['a', 'b', 'c', 'd']),
\CachingIterator::FULL_CACHE);
$shortRange = range(0, 1);
foreach ($shortRange as $index) {
$cache->next();
}
echo PHP_EOL . '快取' . PHP_EOL;
var_export($cache->getCache());
echo PHP_EOL;
echo $cache->offsetGet('1') . PHP_EOL;
echo $cache->offsetGet('2') . PHP_EOL;
?>
快取
array (
0 => 'a',
1 => 'b',
)
b
未定義的索引:2