The returned value from getInnerIterator() really is the inner iterator, not a clone. It should be used with respect: calling next() or rewind() on it, for example, will advance or reset the inner iterator - although the effect won't be noticed until you call next() on the IteratorIterator object - it seems as if it caches its current() and key() values (as of PHP v5.5.9). Even if the inner iterator itself is valid (i.e. valid() returns TRUE) the IteratorIterator won't report itself as valid until you either rewind it or call its next() method - these two methods cause the IteratorIterator to re-sync its current, key and valid states with the inner iterator.
<?php
$ii = new IteratorIterator(new ArrayIterator(range(1,6)));
$i1 = $ii->getInnerIterator(); // gets the real thing
$i2 = $ii->getInnerIterator(); // ditto: $i2 === $i1 and the two are therefore in sync.
echo $i1->current(); // 1
echo $i1->key(); // 0
var_dump($ii->valid()); // FALSE
$i1->next(); // affects $i2, which is identical
echo $i1->key(); // 1
var_dump($ii->valid()); // still FALSE
$ii->rewind(); // rewinds $i1 and synchronizes
echo $ii->key(); // 0, as is $i1->key()
$i1->next(); // advances the inner iterator, which is now out of sync
echo $ii->key(); // still 0
echo $i1->key(); // 1
$ii->next(); // advances the inner iterator and syncs with it
echo $ii->key(); // 2
echo $i1->key(); // 2
?>
PHP.mk документација
IteratorIterator::getInnerIterator
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
iteratoriterator.getinneriterator.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
iteratoriterator.getinneriterator.php
IteratorIterator::getInnerIterator
Референца за `iteratoriterator.getinneriterator.php` со подобрена типографија и навигација.
IteratorIterator::getInnerIterator
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
IteratorIterator::getInnerIterator — Земи го внатрешниот итератор
Параметри
Оваа функција нема параметри.
Вратени вредности
Внатрешниот итератор како што е предаден на (PHP 5 >= 5.1.0, PHP 7, PHP 8), или null кога нема внатрешен итератор.
Белешки од корисници 1 белешка
c точка 1 на smithies точка org ¶
пред 9 години