The CachingIterator class

Introduction

This object supports cached iteration over another iterator.

A CachingIterator is always one element ahead of its inner iterator: when it moves to an element, it stores the key and value of that element, and then moves the inner iterator forward. This makes it possible to know whether the current element is the last one, with CachingIterator::hasNext.

With the CachingIterator::FULL_CACHE flag, it also keeps every element that has been iterated over, which can then be accessed with array syntax or retrieved with CachingIterator::getCache.

Class synopsis

CachingIterator
extends IteratorIterator
implements ArrayAccess Countable Stringable
/* Constants */
public const int CachingIterator::CALL_TOSTRING;
public const int CachingIterator::CATCH_GET_CHILD;
public const int CachingIterator::TOSTRING_USE_KEY;
public const int CachingIterator::TOSTRING_USE_CURRENT;
public const int CachingIterator::TOSTRING_USE_INNER;
public const int CachingIterator::FULL_CACHE;
/* Methods */
public CachingIterator::__construct(Iterator $iterator, int $flags = CachingIterator::CALL_TOSTRING)
public int CachingIterator::count()
public mixed CachingIterator::current()
public array CachingIterator::getCache()
public int CachingIterator::getFlags()
public bool CachingIterator::hasNext()
public mixed CachingIterator::key()
public void CachingIterator::next()
public bool CachingIterator::offsetExists(string $key)
public mixed CachingIterator::offsetGet(string $key)
public void CachingIterator::offsetSet(string $key, mixed $value)
public void CachingIterator::offsetUnset(string $key)
public void CachingIterator::rewind()
public void CachingIterator::setFlags(int $flags)
public string CachingIterator::__toString()
public bool CachingIterator::valid()
/* Inherited methods */
public mixed current()
public Iteratornull getInnerIterator()
public mixed key()
public void next()
public void rewind()
public bool valid()

Predefined Constants

CachingIterator::CALL_TOSTRING

Convert every element to string.

CachingIterator::CATCH_GET_CHILD

Don't throw exception in accessing children.

CachingIterator::TOSTRING_USE_KEY

Use key for conversion to string.

CachingIterator::TOSTRING_USE_CURRENT

Use current for conversion to string.

CachingIterator::TOSTRING_USE_INNER

Use inner for conversion to string.

CachingIterator::FULL_CACHE

Cache all read data.

Changelog

Version Description
8.0.0 CachingIterator implements Stringable now.

Changelog

Version Description
8.4.0 The class constants are now typed.
Table of Contents