3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements ArrayAccess { public function offsetGet($x) { var_dump($x); } public function offsetExists($x) { var_dump($x); } public function offsetSet($x, $y) { var_dump($x); } public function offsetUnset($x) { var_dump($x); } } $foo = new Foo(); echo "$foo[0]"; echo "$foo[1]"; echo "$foo[00]"; echo "$foo[-0]"; echo "$foo[-1]"; //echo "$foo[-00]"; //echo "$foo[-001]";
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of Foo::offsetExists($x) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 7 Deprecated: Return type of Foo::offsetGet($x) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 4 Deprecated: Return type of Foo::offsetSet($x, $y) 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/r699v on line 10 Deprecated: Return type of Foo::offsetUnset($x) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 13 int(0) int(1) string(2) "00" string(2) "-0" int(-1)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of Foo::offsetExists($x) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 7 Deprecated: Return type of Foo::offsetGet($x) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 4 Deprecated: Return type of Foo::offsetSet($x, $y) 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/r699v on line 10 Deprecated: Return type of Foo::offsetUnset($x) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/r699v on line 13 int(0) int(1) string(2) "00" string(2) "-0" int(-1)
Output for 7.1.5 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
int(0) int(1) string(2) "00" string(2) "-0" int(-1)
Output for 7.1.0
int(0) int(1) string(2) "00" int(0) int(-1)
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
Parse error: syntax error, unexpected '-', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /in/r699v on line 23
Process exited with code 255.

preferences:
194.63 ms | 402 KiB | 191 Q