3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements ArrayAccess { public function offsetGet($offset){ var_dump($offset); } public function offsetSet($offset, $value){} public function offsetUnset($offset){} public function offsetExists($offset){} } $o = new Test(); $o[1]; $o['1']; $o[1.0]; $o[new \stdClass()]; $a = ['a', 'b', 'c']; echo $a[1]; echo $a['1']; echo $a[1.0]; echo $a[new \stdClass()];
Output for 8.3.0 - 8.3.7
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/piJL6 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/piJL6 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/piJL6 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/piJL6 on line 10 int(1) string(1) "1" float(1) object(stdClass)#2 (0) { } bbb Fatal error: Uncaught TypeError: Cannot access offset of type stdClass on array in /in/piJL6:25 Stack trace: #0 {main} thrown in /in/piJL6 on line 25
Process exited with code 255.
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19
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/piJL6 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/piJL6 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/piJL6 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/piJL6 on line 10 int(1) string(1) "1" float(1) object(stdClass)#2 (0) { } bbb Fatal error: Uncaught TypeError: Illegal offset type in /in/piJL6:25 Stack trace: #0 {main} thrown in /in/piJL6 on line 25
Process exited with code 255.
Output for 8.0.0 - 8.0.30
int(1) string(1) "1" float(1) object(stdClass)#2 (0) { } bbb Fatal error: Uncaught TypeError: Illegal offset type in /in/piJL6:25 Stack trace: #0 {main} thrown in /in/piJL6 on line 25
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
int(1) string(1) "1" float(1) object(stdClass)#2 (0) { } bbb Warning: Illegal offset type in /in/piJL6 on line 25
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
int(1) int(1) float(1) object(stdClass)#2 (0) { } bbb Warning: Illegal offset type in /in/piJL6 on line 25

preferences:
276.32 ms | 403 KiB | 332 Q