<?php
class lazyNew implements Iterator {
private $obj = null;
private $func ;
public function __construct($func) {
$this->func = $func;
}
public function init() {
if ($this->obj === null) {
$func = $this->func;
$this->obj = $func();
}
return $this->obj;
}
public function current() {
return $this->init()->current();
}
public function valid() {
echo "valid on ".get_class($this)."\n";
//also try var_dump($this)
return $this->init()->valid();
}
public function next() {
return $this->init()->next();
}
public function key() {
return $this->init()->key();
}
public function rewind() {
echo "rewind on ".get_class($this)."\n";
return $this->init()->rewind();
}
}
$P = new lazyNew(function() use (&$P) {
return $P = new ArrayIterator(array(1,2,3,4,5));
});
foreach ($P as $val) echo($val);
?>
Deprecated: Return type of lazyNew::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 15
Deprecated: Return type of lazyNew::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 23
Deprecated: Return type of lazyNew::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 26
Deprecated: Return type of lazyNew::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 18
Deprecated: Return type of lazyNew::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 29
rewind on lazyNew
valid on lazyNew
1valid on lazyNew
2valid on lazyNew
3valid on lazyNew
4valid on lazyNew
5valid on lazyNew
rewind on lazyNew
valid on ArrayIterator
Fatal error: Call to undefined method ArrayIterator::init() in /in/ZcpQZ on line 21
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/ZcpQZ on line 36
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/ZcpQZ on line 36
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/ZcpQZ on line 2
Process exited with code 255.