3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = []; public function fill($limit = 100) { for ($i = 0; $i < $limit; $i++) { $this->bar[] = mt_rand($i, $limit); } } public function getEvenCounter() : Countable { return function () implements Countable { $counter = 0; foreach ($this->bar as $value) { if ($value % 2 === 0) $counter++; } return $counter; }; } public function getOddCounter() : Countable { return function () implements Countable { $counter = 0; foreach ($this->bar as $value) { if ($value % 2 !== 0) { $counter++; } } return $counter; }; } } $foo = new Foo(); $even = $foo->getEvenCounter(); $odd = $foo->getOddCounter(); $it = 0; while (++$it<10) { $foo->fill(50); var_dump( count($even), count($odd)); } ?>
Output for 7.0.0 - 7.0.5
Parse error: syntax error, unexpected 'implements' (T_IMPLEMENTS), expecting '{' in /in/b4AWq on line 12
Process exited with code 255.
Output for 5.5.0 - 5.5.34, 5.6.0 - 5.6.20
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/b4AWq on line 11
Process exited with code 255.

preferences:
187.46 ms | 1395 KiB | 68 Q