3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $x = new class() { public $callCounters = []; public function call($index) { if (!isset($this->callCounters[$index])) { $this->callCounters[$index] = 0; } ++$this->callCounters[$index]; } }; $indexes = range('a','e'); foreach($indexes as $index) { for($i = 0; $i <= 2; ++$i) { $x->call($index); } } var_dump($x->callCounters);
based on L3NqP
Output for hhvm-3.15.4, 7.0.0 - 7.2.6
array(5) { ["a"]=> int(3) ["b"]=> int(3) ["c"]=> int(3) ["d"]=> int(3) ["e"]=> int(3) }
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/3sA0F on line 3
Process exited with code 255.