3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myIterator implements Iterator { public $bar = [5, 4, 3, 2, 1]; public function valid() { return $this->key() !== null; } public function current() { return current($this->bar); } public function key() { return key($this->bar); } public function next() { return next($this->bar); } public function rewind() { rewind($this->bar); } } $it = new myIterator(); while ($it->valid()) { var_dump($it->current()); $it->next(); }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Deprecated: Return type of myIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bmUvv on line 11 Deprecated: Return type of myIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bmUvv on line 19 Deprecated: Return type of myIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bmUvv on line 15 Deprecated: Return type of myIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bmUvv on line 7 Deprecated: Return type of myIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bmUvv on line 23 int(5) int(4) int(3) int(2) int(1)
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
int(5) int(4) int(3) int(2) int(1)

preferences:
171.12 ms | 409 KiB | 5 Q