3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements ArrayAccess { private $data = array(); /** Array Access */ public function offsetExists($offset) { return isset($this->data[$offset]); } public function &offsetGet($offset) { return $this->data[$offset]; } public function offsetSet($offset, $value) { $this->data[$offset] = $value; } public function offsetUnset($offset) { unset($this->data[$offset]); } } class Test2 extends ArrayObject { public function &offsetGet($offset) { $t =& parent::offsetGet($offset); return $t; } } $t = new Test(); $t['test'] = array(1,2,3,4); echo serialize($t)."\n"; $t['test'][] = 5; echo serialize($t)."\n"; $t = new Test2(); $t['test'] = array(1,2,3,4); echo serialize($t)."\n"; $t['test'][] = 5; echo serialize($t)."\n";

preferences:
32.83 ms | 402 KiB | 5 Q