3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myIterator implements Iterator { private $position = 0; private $array = array( "firstelement_Iterator", "secondelement_Iterator", "lastelement_Iterator", ); public function __construct() { $this->position = 0; } 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]); } } $test = new myIterator(); echo "start test $testName\n"; $current = current($test); $i = 0; $current = current($test); foreach ($test as $key => $value) { //echo "$key, $value \n"; } //current returns the value of the array element that's currently being pointed to by the // internal pointer. // If the internal pointer points beyond the end of the elements list or the array is empty, current() returns FALSE. var_dump(current($test)); // reset() rewinds array's internal pointer to the first element and // returns the value of the first array element - this should be firstelement_* var_dump(reset($test)); echo "End test.\n\n";
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
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/C6MvK on line 21 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/C6MvK on line 29 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/C6MvK on line 25 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/C6MvK on line 33 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/C6MvK on line 17 Warning: Undefined variable $testName in /in/C6MvK on line 46 start test Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 48 Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 51 Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 59 int(3) Deprecated: reset(): Calling reset() on an object is deprecated in /in/C6MvK on line 62 int(3) End test.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $testName in /in/C6MvK on line 46 start test int(3) int(3) End test.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: testName in /in/C6MvK on line 46 start test int(3) int(3) End test.
Output for 7.3.32 - 7.3.33
start test int(3) int(3) End test.

preferences:
221.94 ms | 401 KiB | 256 Q