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
Output for 8.3.0 - 8.3.4
Deprecated: Return type of Test::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 11 Deprecated: Return type of Test::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 5 Deprecated: Return type of Test::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 9 Deprecated: Return type of Test::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 10 integer string double string object b b b b Fatal error: Uncaught TypeError: Cannot access offset of type Test on array in /in/ADU57:28 Stack trace: #0 {main} thrown in /in/ADU57 on line 28
Process exited with code 255.
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17
Deprecated: Return type of Test::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 11 Deprecated: Return type of Test::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 5 Deprecated: Return type of Test::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 9 Deprecated: Return type of Test::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ADU57 on line 10 integer string double string object b b b b Fatal error: Uncaught TypeError: Illegal offset type in /in/ADU57:28 Stack trace: #0 {main} thrown in /in/ADU57 on line 28
Process exited with code 255.
Output for 8.0.0 - 8.0.30
integer string double string object b b b b Fatal error: Uncaught TypeError: Illegal offset type in /in/ADU57:28 Stack trace: #0 {main} thrown in /in/ADU57 on line 28
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
integer string double string object b b b b Warning: Illegal offset type in /in/ADU57 on line 28
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
integer integer double string object b b b b Warning: Illegal offset type in /in/ADU57 on line 28

preferences:
157.72 ms | 402 KiB | 193 Q