3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CSVFileIterator implements Iterator{ protected $_index = 0; function __construct() { } /** * (PHP 5 >= 5.0.0)<br/> * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. */ public function current() { return $this->_index; } /** * (PHP 5 >= 5.0.0)<br/> * Move forward to next element * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. */ public function next() { var_dump('next'); $this->_index++; } /** * (PHP 5 >= 5.0.0)<br/> * Return the key of the current element * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. */ public function key() { var_dump('key'); return $this->_index; } /** * (PHP 5 >= 5.0.0)<br/> * Checks if current position is valid * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. */ public function valid() { var_dump('valid'); return $this->_index <5; } /** * (PHP 5 >= 5.0.0)<br/> * Rewind the Iterator to the first element * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. */ public function rewind() { var_dump('rewind'); $this->_index = 0; } } $i = new CSVFileIterator(); foreach ($i as $j);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of CSVFileIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Hd51L on line 17 Deprecated: Return type of CSVFileIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Hd51L on line 28 Deprecated: Return type of CSVFileIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Hd51L on line 40 Deprecated: Return type of CSVFileIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Hd51L on line 53 Deprecated: Return type of CSVFileIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Hd51L on line 65 string(6) "rewind" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid"
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(6) "rewind" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid" string(4) "next" string(5) "valid"
Output for 5.0.0 - 5.0.5
string(6) "rewind" string(5) "valid" string(3) "key" string(4) "next" string(5) "valid" string(3) "key" string(4) "next" string(5) "valid" string(3) "key" string(4) "next" string(5) "valid" string(3) "key" string(4) "next" string(5) "valid" string(3) "key" string(4) "next" string(5) "valid"
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/Hd51L on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/Hd51L on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/Hd51L on line 2
Process exited with code 255.

preferences:
281.88 ms | 401 KiB | 356 Q