class IteratorIterator implements OuterIterator (View source)

This iterator wrapper allows the conversion of anything that is Traversable into an Iterator.

It is important to understand that most classes that do not implement Iterators have reasons as most likely they do not allow the full Iterator feature set. If so, techniques should be provided to prevent misuse, otherwise expect exceptions or fatal errors.

Methods

__construct(Traversable $iterator, string|null $class = null)

Create an iterator from anything that is traversable

Iterator|null
getInnerIterator()

Get the inner iterator

void
rewind()

Rewind to the first element

bool
valid()

Checks if the iterator is valid

mixed
key()

Get the key of the current element

mixed
current()

Get the current value

void
next()

Forward to the next element

Details

__construct(Traversable $iterator, string|null $class = null)

Create an iterator from anything that is traversable

Parameters

Traversable $iterator
string|null $class [optional]

Iterator|null getInnerIterator()

Get the inner iterator

Return Value

Iterator|null

The inner iterator for the current entry.

void rewind()

Rewind to the first element

Return Value

void

Any returned value is ignored.

bool valid()

Checks if the iterator is valid

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

mixed key()

Get the key of the current element

Return Value

mixed

TKey on success, or null on failure.

mixed current()

Get the current value

Return Value

mixed

Can return any type.

void next()

Forward to the next element

Return Value

void

Any returned value is ignored.