3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Cars implements Iterator { private $pointer = 0; private $array = array(); public function __construct() { $this->pointer = 0; } public function addCar($car) { array_push($this->array, $car); } function rewind() { $this->pointer = 0; } function current() { return $this->array[$this->pointer]; } function key() { return $this->pointer; } function next() { ++$this->pointer; } public function valid() { return isset($this->array[$this->pointer]); } } $car = new Cars; $car->addCar("Volvo"); $car->addCar("BMW"); $car->addCar("Mercedes"); foreach ($car as $key => $value) { echo $key . ": " . $value . "<br />"; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of Cars::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UPZOs on line 15 Deprecated: Return type of Cars::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UPZOs on line 21 Deprecated: Return type of Cars::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UPZOs on line 18 Deprecated: Return type of Cars::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UPZOs on line 24 Deprecated: Return type of Cars::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UPZOs on line 12 0: Volvo<br />1: BMW<br />2: Mercedes<br />
Output for 5.6.0 - 5.6.24, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
0: Volvo<br />1: BMW<br />2: Mercedes<br />

preferences:
190.99 ms | 403 KiB | 182 Q