(PHP 5, PHP 7, PHP 8)
CachingIterator::__construct — Construct a new CachingIterator object for the iterator
$iterator, int $flags = CachingIterator::CALL_TOSTRING)
Creates a CachingIterator that iterates over
iterator, staying one element ahead of it.
iteratorThe iterator to cache.
flagsA bitmask of the CachingIterator constants.
At most one of CachingIterator::CALL_TOSTRING,
CachingIterator::TOSTRING_USE_KEY,
CachingIterator::TOSTRING_USE_CURRENT and
CachingIterator::TOSTRING_USE_INNER may be given.
It selects what CachingIterator::__toString()
returns; if none of them is given, calling it throws an exception.
CachingIterator::FULL_CACHE keeps every element
that has been iterated over, so that it can be accessed with
array syntax
or retrieved with CachingIterator::getCache().
Throws a ValueError if
flags contains more than one of
CachingIterator::CALL_TOSTRING,
CachingIterator::TOSTRING_USE_KEY,
CachingIterator::TOSTRING_USE_CURRENT and
CachingIterator::TOSTRING_USE_INNER.
| Version | Description |
|---|---|
| 8.0.0 |
Now throws a ValueError if
flags contains more than one of the string
conversion flags; previously, an
InvalidArgumentException was thrown.
|
With CachingIterator::CALL_TOSTRING, which is the
default, each element is converted to a string as soon as the iterator
moves to it, whether or not
CachingIterator::__toString() is ever called.
An element that is an array raises an E_WARNING,
and an object that does not implement
__toString() throws an
Error.
To iterate over such elements, pass flags that do
not contain CachingIterator::CALL_TOSTRING, such as
0.