3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Record { protected $index=0; //page index protected $pages=[]; //pages array public function nextPage() { $this->index++; } public function addRecord($key, $value) { $this->pages[$this->index][$key] = $value; } public function getPage($index) { if ($index > $this->index) return NULL; else return $this->pages[$this->index]; } } class AdditiveRecord extends Record { public function getSums($range) { $sums = $this->pages[$range[0]]; $lim = ($range[1] <= $this->index) ? $range[1] : $this->index; echo $lim; echo $index; for ($i = $range[0]+1;$i<=$lim;$i++) { foreach($this->pages[$i] as $k=>$v) $sums[$k] += $v; } return $sums; } } $m = new AdditiveRecord(); for ($j = 1;$j<3;$j++) { for ($i = 1;$i<10;$i++) $m->addRecord($i,$j*10+$i); $m->nextPage(); } var_dump($m->getSums([0,2]));
based on rJpeH
Output for 5.4.0 - 7.2.0
2 Notice: Undefined variable: index in /in/eFFek on line 26 Notice: Undefined offset: 2 in /in/eFFek on line 28 Warning: Invalid argument supplied for foreach() in /in/eFFek on line 28 array(9) { [1]=> int(32) [2]=> int(34) [3]=> int(36) [4]=> int(38) [5]=> int(40) [6]=> int(42) [7]=> int(44) [8]=> int(46) [9]=> int(48) }
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/eFFek on line 5
Process exited with code 255.