3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Record { private $index=0; //page index private $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]; } } $r = new Record(); $r->addRecord("t","m"); var_dump($r->getPage(0));
based on 0idGA
Output for 7.1.0 - 7.2.0
Notice: Undefined variable: pages in /in/MQMgP on line 12 Notice: Undefined offset: 0 in /in/MQMgP on line 18 NULL
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: pages in /in/MQMgP on line 12 Fatal error: Uncaught Error: Cannot access empty property in /in/MQMgP:12 Stack trace: #0 /in/MQMgP(23): Record->addRecord('t', 'm') #1 {main} Next Error: Cannot access empty property in /in/MQMgP:12 Stack trace: #0 /in/MQMgP(23): Record->addRecord('t', 'm') #1 {main} thrown in /in/MQMgP on line 12
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Notice: Undefined variable: pages in /in/MQMgP on line 12 Fatal error: Cannot access empty property in /in/MQMgP on line 12
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/MQMgP on line 6
Process exited with code 255.