3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Data implements \ArrayAccess { private $_data; public function __construct($data = []) { $this->_data = $data; } public function offsetExists($offset) { echo 'EXISTS: ' . $offset . PHP_EOL; return isset($this->_data[$offset]); } public function &offsetGet($offset) { echo 'GET: ' . $offset . PHP_EOL; $returnValue = null; if (!isset($this->_data[$offset])) { $this->_data[$offset]=new Data(); //return new ; } $returnValue = &$this->_data[$offset]; return $returnValue; } public function offsetSet($offset, $value) { echo 'SET: ' . $offset . PHP_EOL; var_dump($value); $this->_data[$offset] = $value; } public function offsetUnset($offset) { unset($this->_data[$offset]); } } $data = new Data(); var_dump(isset($data['aaaaa']['bbbbbb']['ccccc'])); $data['aaaaa']['bbbbbb']['ccccc'];//='dddddd'; var_dump($data);
based on Bh56V
Output for 7.0.6 - 7.2.0
EXISTS: aaaaa bool(false) GET: aaaaa GET: bbbbbb GET: ccccc object(Data)#1 (1) { ["_data":"Data":private]=> array(1) { ["aaaaa"]=> object(Data)#2 (1) { ["_data":"Data":private]=> array(1) { ["bbbbbb"]=> object(Data)#3 (1) { ["_data":"Data":private]=> array(1) { ["ccccc"]=> object(Data)#4 (1) { ["_data":"Data":private]=> array(0) { } } } } } } } }
Output for 5.4.9 - 7.0.5
GET: aaaaa GET: bbbbbb EXISTS: ccccc bool(false) GET: aaaaa GET: bbbbbb GET: ccccc object(Data)#1 (1) { ["_data":"Data":private]=> array(1) { ["aaaaa"]=> object(Data)#2 (1) { ["_data":"Data":private]=> array(1) { ["bbbbbb"]=> object(Data)#3 (1) { ["_data":"Data":private]=> array(1) { ["ccccc"]=> object(Data)#4 (1) { ["_data":"Data":private]=> array(0) { } } } } } } } }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LVfi6 on line 8
Process exited with code 255.