3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements ArrayAccess { public function offsetGet($offset){ return gettype($offset); } public function offsetSet($offset, $value){} public function offsetUnset($offset){} public function offsetExists($offset){} } $a = array('a', 'b', 'c'); $o = new Test(); $s = '1'; echo $o[1], "\n"; // 'integer' echo $o['1'], "\n"; // 'integer' !? echo $o[1.0], "\n"; // 'double' echo $o[$s], "\n"; // 'string' echo $o[$o], "\n"; // 'object' echo $a[1], "\n"; // 'integer' echo $a['1'], "\n"; // 'integer' echo $a[1.0], "\n"; // 'integer' echo $a[$s], "\n"; // 'integer' echo $a[$o], "\n"; // Warning: Illegal offset type
based on ADU57
Output for 8.0.0 - 8.0.3
integer string double string object b b b b Fatal error: Uncaught TypeError: Illegal offset type in /in/0BMYh:28 Stack trace: #0 {main} thrown in /in/0BMYh on line 28
Process exited with code 255.
Output for 7.3.0 - 7.3.28, 7.4.0 - 7.4.16
integer string double string object b b b b Warning: Illegal offset type in /in/0BMYh on line 28
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
integer integer double string object b b b b Warning: Illegal offset type in /in/0BMYh on line 28