3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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";
Output for 7.0.0 - 7.1.0
O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}}} O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}}} C:5:"Test2":70:{x:i:0;a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}};m:a:0:{}} Notice: Only variables should be assigned by reference in /in/qdJEZ on line 31 C:5:"Test2":70:{x:i:0;a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}};m:a:0:{}}
Output for 5.3.4 - 5.6.28
O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}}} O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}}} C:5:"Test2":70:{x:i:0;a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}};m:a:0:{}} Strict Standards: Only variables should be assigned by reference in /in/qdJEZ on line 31 Notice: Indirect modification of overloaded element of Test2 has no effect in /in/qdJEZ on line 45 C:5:"Test2":70:{x:i:0;a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}};m:a:0:{}}
Output for 5.1.0 - 5.3.3
Fatal error: Declaration of Test2::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /in/qdJEZ on line 34
Process exited with code 255.
Output for 5.0.5
O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}}} O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}}} O:5:"Test2":1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}} Strict Standards: Only variables should be assigned by reference in /in/qdJEZ on line 31 Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /in/qdJEZ on line 45
Process exited with code 255.
Output for 5.0.0 - 5.0.4
O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}}} O:4:"Test":1:{s:10:"Testdata";a:1:{s:4:"test";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}}} O:5:"Test2":1:{s:4:"test";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}} Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /in/qdJEZ on line 45
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/qdJEZ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/qdJEZ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/qdJEZ on line 3
Process exited with code 255.