3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class X implements ArrayAccess { var $x = 42; function &offsetGet($n) { var_dump(0,$n); return $this->x;} function offsetSet($x, $z) { var_dump($x, $z); var_dump(1, $this->x); } function offsetExists($n) {} function offsetUnset($n) {} } $x = new X(); $x[23]++;
based on RcluA
Output for 5.3.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
int(0) int(23)
Output for 5.1.3 - 5.3.3
Fatal error: Declaration of X::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /in/o2pVl on line 2
Process exited with code 255.
Output for 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/o2pVl on line 3 Fatal error: Declaration of X::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /in/o2pVl on line 2
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/o2pVl on line 3 int(0) int(23)
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/o2pVl on line 2
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/o2pVl on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/o2pVl on line 2
Process exited with code 255.