final class Generator implements Iterator (View source)

Generator objects are returned from generators, cannot be instantiated via new.

Methods

void
rewind()

Throws an exception if the generator is currently after the first yield.

bool
valid()

Returns false if the generator has been closed, true otherwise.

mixed
current()

Returns whatever was passed to yield or null if nothing was passed or the generator is already closed.

mixed
key()

Returns the yielded key or, if none was specified, an auto-incrementing key or null if the generator is already closed.

void
next()

Resumes the generator (unless the generator is already closed).

mixed
send(mixed $value)

Sets the return value of the yield expression and resumes the generator (unless the generator is already closed).

mixed
PS_UNRESERVE_PREFIX_throw(Throwable $exception)

Throws an exception at the current suspension point in the generator.

mixed
getReturn()

Returns whatever was passed to return or null if nothing.

void
__wakeup()

Serialize callback Throws an exception as generators can't be serialized.

array
__debugInfo()

No description

Details

void rewind()

Throws an exception if the generator is currently after the first yield.

Return Value

void

Any returned value is ignored.

bool valid()

Returns false if the generator has been closed, true otherwise.

Return Value

bool

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

mixed current()

Returns whatever was passed to yield or null if nothing was passed or the generator is already closed.

Return Value

mixed

Can return any type.

mixed key()

Returns the yielded key or, if none was specified, an auto-incrementing key or null if the generator is already closed.

Return Value

mixed

TKey on success, or null on failure.

void next()

Resumes the generator (unless the generator is already closed).

Return Value

void

Any returned value is ignored.

mixed send(mixed $value)

Sets the return value of the yield expression and resumes the generator (unless the generator is already closed).

Parameters

mixed $value

Return Value

mixed

mixed PS_UNRESERVE_PREFIX_throw(Throwable $exception)

Throws an exception at the current suspension point in the generator.

Parameters

Throwable $exception

Return Value

mixed

mixed getReturn()

Since: 7.0

Returns whatever was passed to return or null if nothing.

Throws an exception if the generator is still valid.

Return Value

mixed

void __wakeup()

Serialize callback Throws an exception as generators can't be serialized.

Return Value

void

array __debugInfo()

Since: 8.4

No description

Return Value

array