php-src/Zend/zend_interfaces.stub.php
Nikita Popov ff19ec2df3 Introduce InternalIterator
Userland classes that implement Traversable must do so either
through Iterator or IteratorAggregate. The same requirement does
not exist for internal classes: They can implement the internal
get_iterator mechanism, without exposing either the Iterator or
IteratorAggregate APIs. This makes them usable in get_iterator(),
but incompatible with any Iterator based APIs.

A lot of internal classes do this, because exposing the userland
APIs is simply a lot of work. This patch alleviates this issue by
providing a generic InternalIterator class, which acts as an
adapater between get_iterator and Iterator, and can be easily
used by many internal classes. At the same time, we extend the
requirement that Traversable implies Iterator or IteratorAggregate
to internal classes as well.

Closes GH-5216.
2020-06-24 15:31:41 +02:00

83 lines
1.5 KiB
PHP

<?php
/** @generate-function-entries */
interface Traversable {}
interface IteratorAggregate extends Traversable
{
/** @return Traversable */
public function getIterator();
}
interface Iterator extends Traversable
{
/** @return mixed */
public function current();
/** @return void */
public function next();
/** @return mixed */
public function key();
/** @return bool */
public function valid();
/** @return void */
public function rewind();
}
interface ArrayAccess
{
/** @return bool */
public function offsetExists($offset);
/* actually this should be return by ref but atm cannot be */
/** @return mixed */
public function offsetGet($offset);
/** @return void */
public function offsetSet($offset, $value);
/** @return void */
public function offsetUnset($offset);
}
interface Serializable
{
/** @return string */
public function serialize();
/** @return void */
public function unserialize(string $serialized);
}
interface Countable
{
/** @return int */
public function count();
}
interface Stringable
{
public function __toString(): string;
}
final class InternalIterator implements Iterator
{
private function __construct();
/** @return mixed */
public function current();
/** @return mixed */
public function key();
public function next(): void;
public function valid(): bool;
public function rewind(): void;
}