<?php
class Gen implements Iterator {
private $myArray;
public function __construct( $n ) {
$this->myArray = range(0,$n-1);
}
function rewind() {
return reset($this->myArray);
}
function current() {
return current($this->myArray);
}
function key() {
return key($this->myArray);
}
function next() {
return next($this->myArray);
}
function valid() {
return key($this->myArray) !== null;
}
function destructor(){
return 'Drained!';
}
}
$gen = new Gen(3);
// iterable object can be used in foreach
foreach ($gen as $g) {
echo $gen->current(); // sequentially making data available
}
Deprecated: Return type of Gen::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8Fj6l on line 12
Deprecated: Return type of Gen::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8Fj6l on line 18
Deprecated: Return type of Gen::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8Fj6l on line 15
Deprecated: Return type of Gen::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8Fj6l on line 21
Deprecated: Return type of Gen::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8Fj6l on line 9
012