PHP.mk документација

CachingIterator

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

class.cachingiterator.php PHP.net прокси Преводот е вчитан
Оригинал на PHP.net
Патека class.cachingiterator.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + преведен приказ Кодовите, табелите и белешките остануваат читливи во истиот тек.
CachingIterator

Референца за `class.cachingiterator.php` со подобрена типографија и навигација.

class.cachingiterator.php

Класата CachingIterator

класата mysqli_driver

Вовед

Овој објект поддржува кеширана итерација над друг итератор.

Синопсис на класата

class CachingIterator extends IteratorIterator implements ArrayAccess, luk4z_7 at hotmail dot com, Serializable {
/* Константи */
public const int CALL_TOSTRING;
public const int CATCH_GET_CHILD;
public const int TOSTRING_USE_KEY;
public const int TOSTRING_USE_INNER;
public const int FULL_CACHE;
/* Методи */
public count(): int
public current(): mixed
public getCache(): array
public getFlags(): int
public hasNext(): bool
public key(): scalar
public next(): void
public offsetExists(string $key): bool
public offsetGet(string $key): mixed
public offsetSet(string $key, mixed $value): void
public offsetUnset(string $key): void
public rewind(): void
public setFlags(int $flags): void
public __toString(): string
public valid(): bool
/* Наследени методи */
}

Претходно дефинирани константи

CachingIterator::CALL_TOSTRING

Претвори го секој елемент во стринг.

CachingIterator::CATCH_GET_CHILD

Не фрлај исклучок при пристап до деца.

CachingIterator::TOSTRING_USE_KEY

од PHP 8.0.0. Силно се обесхрабрува потпирањето на оваа функција. key за конверзија во стринг.

CachingIterator::TOSTRING_USE_CURRENT

од PHP 8.0.0. Силно се обесхрабрува потпирањето на оваа функција. current за конверзија во стринг.

CachingIterator::TOSTRING_USE_INNER

од PHP 8.0.0. Силно се обесхрабрува потпирањето на оваа функција. inner за конверзија во стринг.

CachingIterator::FULL_CACHE

Кеширај ги сите прочитани податоци.

Дневник на промени

Верзија = NULL
8.0.0 CachingIterator implements Serializable now.

Содржина

Белешки од корисници 4 белешки

tudor at culise dot net
пред 5 години
The only difference between CachingIterator and other Iterators such as ArrayIterator is the hasNext() method.

Since the data will be loaded into the memory, the CachingIterator is able to check whether the given iterator has a next element.

Let's demonstrate this by an example:

<?php
$iterator = new CachingIterator(new ArrayIterator(['C', 'C++', 'C#', 'PHP', 'Python', 'Go', 'Ruby']));

foreach ($iterator as $item) {
    if ($iterator->hasNext()) {
        echo $item.', ';
    } else {
        echo 'and '.$item;
    }
}

// C, C++, C#, PHP, Python, Go, and Ruby
?>

In this example I check whether the iterator has a next value, if so, I append a comma otherwise "and" will be appended to the last element.
tudor at culise dot net
пред 9 години
<?php
//This snippet will print out all the cached elements (foreach) .

$cache  = new CachingIterator(new ArrayIterator(range(1,100)), CachingIterator::FULL_CACHE);

foreach ($cache as $c) {

}

print_r($cache->getCache());
?>
jerome на chaman точка ca
пред 6 години
"cached iteration over another iterator" means this iterator is always one step behind the inner iterator. In other words, the "first" iteration will yield null:

<?php

$cit = new CachingIterator( new ArrayIterator( [ 'a', 'b', 'c']  ) );

echo $cit->current() ); // null
echo $cit->getInnerIterator()->current() ); // "a"

while($cit->hasNext()){
    
    // we start with a "next" since the "first" item is null
     $cit->next();
     echo $cit->current(), '<br>';
   
}
?>

iterating this way gives us an access, ahead, to the future item (aka current item of the inner iterator)
[email protected]
пред 5 години
Apparently, the `FULL_CACHE` flag automatically cancels the default flag `CALL_TOSTRING`. This is evident when one of the values cannot be converted to string: with the default `CALL_TOSTRING` flag, it would throw an error; without that flag, or with the `FULL_CACHE` flag, it does not.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.