3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Outer { protected $data; public function __construct($data) { $this->data = $data; } public function getArrayAccess() { /* create a proxy object implementing array access */ return new class($this->data) extends Outer implements ArrayAccess { public function offsetGet($offset) { return $this->data[$offset]; } public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); } public function offsetUnset($offset) { unset($this->data[$offset]); } public function offsetExists($offset) { return isset($this->data[$offset]); } }; } } $outer = new Outer(array( rand(1, 100) )); /* not null because inheritance */ var_dump($outer->getArrayAccess()[0]);
Output for 7.2.12
int(35)
Output for 7.2.11
int(80)
Output for 7.2.10
int(11)
Output for 7.2.9
int(34)
Output for 7.2.8
int(95)
Output for 7.0.18, 7.1.23, 7.2.7
int(79)
Output for 7.1.19, 7.2.6
int(29)
Output for 7.2.5
int(98)
Output for 7.0.23, 7.2.4
int(86)
Output for 7.2.3
int(61)
Output for 7.1.14, 7.2.2
int(16)
Output for 7.2.1
int(31)
Output for 7.1.12, 7.1.18, 7.2.0
int(71)
Output for 7.0.29, 7.1.0, 7.1.24
int(28)
Output for 7.1.22
int(40)
Output for 7.0.27, 7.1.21
int(45)
Output for 7.1.20
int(85)
Output for 7.1.2, 7.1.5, 7.1.17
int(90)
Output for 7.1.16
int(68)
Output for 7.1.15
int(48)
Output for 7.0.32, 7.1.13
int(8)
Output for 7.1.11
int(44)
Output for 7.0.28, 7.1.10
int(27)
Output for 7.0.5, 7.1.9
int(3)
Output for 7.1.8
int(84)
Output for 7.1.7
int(17)
Output for 7.1.6
int(14)
Output for 7.1.4
int(6)
Output for 7.1.3
int(67)
Output for 7.1.1
int(96)
Output for 7.0.21, 7.0.31
int(81)
Output for 7.0.30
int(58)
Output for 7.0.10, 7.0.26
int(52)
Output for 7.0.25
int(88)
Output for 7.0.24
int(73)
Output for 7.0.13, 7.0.22
int(54)
Output for 7.0.20
int(24)
Output for 7.0.19
int(72)
Output for 7.0.17
int(30)
Output for 7.0.16
int(5)
Output for 7.0.11, 7.0.15
int(1)
Output for 7.0.14
int(46)
Output for 7.0.7, 7.0.12
int(22)
Output for 7.0.4, 7.0.9
int(43)
Output for 7.0.8
int(49)
Output for 7.0.6
int(36)
Output for 7.0.3
int(41)
Output for 7.0.2
int(4)
Output for 7.0.1
int(42)
Output for 7.0.0
int(15)
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/elh6I on line 9
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_CLASS in /in/elh6I on line 9
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/elh6I on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/elh6I on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/elh6I on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/elh6I on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/elh6I on line 3
Process exited with code 255.

preferences:
208.73 ms | 401 KiB | 283 Q