CachingIterator::__construct
(PHP 5, PHP 7, PHP 8)
CachingIterator::__construct — Construct a new CachingIterator object for the iterator
Description
$iterator, int $flags = CachingIterator::CALL_TOSTRING)
Creates a CachingIterator that iterates over
iterator, staying one element ahead of it.
Parameters
iterator
The iterator to cache.
flags
A 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().
Errors/Exceptions
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.
Changelog
| 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.
|
Notes
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.
See Also
- CachingIterator::setFlags() - Set the flags for the CachingIterator object
- CachingIterator::__toString() - Return the string representation of the current element
- RecursiveCachingIterator::__construct() - Construct
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
