mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
ff19ec2df3
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.
83 lines
1.5 KiB
PHP
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;
|
|
}
|