note 124512 added to cachingiterator.offsetset
| From: | ddrake at dreamingmind dot com | Date: | Mon, 16 Dec 2019 03:23:12 +0000 |
| Subject: | note 124512 added to cachingiterator.offsetset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213543@lists.php.net to get a copy of this message | ||
offsetSet($index, $newval) will change an existing cache value or create a new cache entry
<?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 . 'The cache' . PHP_EOL;
var_export($cache->getCache());
echo PHP_EOL;
echo $cache->offsetSet('0', 'manual change') . PHP_EOL;
echo $cache->offsetSet('3', 'manual entry') . PHP_EOL;
?>
The cache
array (
0 => 'a',
1 => 'b',
)
The cache
array (
0 => 'manual change',
1 => 'b',
3 => 'manual entry',
)
There is no requirement that the offset exist in the inner iterator, or that the offset exists in
the cache.
<?php
$cache = new \CachingIterator(
new \ArrayIterator([]),
\CachingIterator::FULL_CACHE);
echo $cache->offsetSet('22', 'manual entry') . PHP_EOL;
echo PHP_EOL . 'The cache' . PHP_EOL;
var_export($cache->getCache());
echo PHP_EOL;
print_r("cache offset '22' " .
($cache->offsetExists('22') == 1
? 'exists'
: "doesn't exist"
) . PHP_EOL);
?>
The cache
array (
22 => 'manual entry',
)
cache offset '22' exists
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 2601:640:4080:5840:6c03:551a:f883:478e)
----
Manual Page -- http://php.net/manual/en/cachingiterator.offsetset.php
Edit -- https://master.php.net/note/edit/124512
Del: integrated -- https://master.php.net/note/delete/124512/integrated
Del: useless -- https://master.php.net/note/delete/124512/useless
Del: bad code -- https://master.php.net/note/delete/124512/bad+code
Del: spam -- https://master.php.net/note/delete/124512/spam
Del: non-english -- https://master.php.net/note/delete/124512/non-english
Del: in docs -- https://master.php.net/note/delete/124512/in+docs
Del: other reasons-- https://master.php.net/note/delete/124512
Reject -- https://master.php.net/note/reject/124512
Search -- https://master.php.net/manage/user-notes.php