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])) { return $returnValue; } $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(); $data['aaaaa']['bbbbbb']['ccccc']='dddddd'; var_dump($data);
based on PTLc8
Output for 7.0.0 - 7.2.0
GET: aaaaa object(Data)#1 (1) { ["_data":"Data":private]=> array(0) { } }
Output for 5.4.9 - 5.6.28
GET: aaaaa Notice: Indirect modification of overloaded element of Data has no effect in /in/ftZX4 on line 49 object(Data)#1 (1) { ["_data":"Data":private]=> array(0) { } }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/ftZX4 on line 8
Process exited with code 255.