3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myData implements IteratorAggregate { public $property1 = "Public property one"; public $property2 = "Public property two"; public $property3 = "Public property three"; public function __construct() { $this->property4 = "last property"; } public function getIterator() { return new ArrayIterator($this); } } class myIterator implements Iterator { private $position = 0; private $array = array('one', 'two', 'three'); function rewind() { $this->position = 0; } function current() { return $this->array[$this->position]; } function key() { return $this->position; } function next() { ++$this->position; } function valid() { return isset($this->array[$this->position]); } } $renderFunction = function($iterator) { foreach($iterator as $key => $value) { echo "$key: $value\n"; foreach($iterator as $key => $value) { echo " $key: $value\n"; } } }; echo "-----IteratorAggregate-----\n"; $renderFunction(new myData); echo "\n-----Iterator-----\n"; $renderFunction(new myIterator);
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Deprecated: Return type of myData::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/JHDNQ on line 13 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/JHDNQ on line 29 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/JHDNQ on line 39 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/JHDNQ on line 34 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/JHDNQ on line 44 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/JHDNQ on line 24 -----IteratorAggregate----- Deprecated: Creation of dynamic property myData::$property4 is deprecated in /in/JHDNQ on line 10 property1: Public property one property1: Public property one property2: Public property two property3: Public property three property4: last property property2: Public property two property1: Public property one property2: Public property two property3: Public property three property4: last property property3: Public property three property1: Public property one property2: Public property two property3: Public property three property4: last property property4: last property property1: Public property one property2: Public property two property3: Public property three property4: last property -----Iterator----- 0: one 0: one 1: two 2: three
Output for 8.1.0 - 8.1.28
Deprecated: Return type of myData::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/JHDNQ on line 13 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/JHDNQ on line 29 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/JHDNQ on line 39 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/JHDNQ on line 34 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/JHDNQ on line 44 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/JHDNQ on line 24 -----IteratorAggregate----- property1: Public property one property1: Public property one property2: Public property two property3: Public property three property4: last property property2: Public property two property1: Public property one property2: Public property two property3: Public property three property4: last property property3: Public property three property1: Public property one property2: Public property two property3: Public property three property4: last property property4: last property property1: Public property one property2: Public property two property3: Public property three property4: last property -----Iterator----- 0: one 0: one 1: two 2: three
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
-----IteratorAggregate----- property1: Public property one property1: Public property one property2: Public property two property3: Public property three property4: last property property2: Public property two property1: Public property one property2: Public property two property3: Public property three property4: last property property3: Public property three property1: Public property one property2: Public property two property3: Public property three property4: last property property4: last property property1: Public property one property2: Public property two property3: Public property three property4: last property -----Iterator----- 0: one 0: one 1: two 2: three

preferences:
225.48 ms | 404 KiB | 302 Q