3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Ar implements ArrayAccess { private $storage = []; private $offset = null; public function __construct(array $ar) { $this->storage = array_values($ar); $this->offset = 0; } public function offsetExists($offset) { return $offset <= count($this->storage); } public function offsetGet($offset) { return $this->storage[$offset]; } public function offsetSet($offset, $value) { $this->storage[$offset] = $value; } public function offsetUnset($offset) { unset($this->storage[$offset]); $this->storage = array_values($this->storage); } } $obj = new Ar([1,2,3,4,5,6,7]); var_dump(array_values($obj));
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 Ar::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/Rh7kg on line 13 Deprecated: Return type of Ar::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/Rh7kg on line 18 Deprecated: Return type of Ar::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/Rh7kg on line 23 Deprecated: Return type of Ar::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/Rh7kg on line 28 Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, Ar given in /in/Rh7kg:37 Stack trace: #0 /in/Rh7kg(37): array_values(Object(Ar)) #1 {main} thrown in /in/Rh7kg on line 37
Process exited with code 255.
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 Ar::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/Rh7kg on line 13 Deprecated: Return type of Ar::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/Rh7kg on line 18 Deprecated: Return type of Ar::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/Rh7kg on line 23 Deprecated: Return type of Ar::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/Rh7kg on line 28 Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, Ar given in /in/Rh7kg:37 Stack trace: #0 /in/Rh7kg(37): array_values(Object(Ar)) #1 {main} thrown in /in/Rh7kg on line 37
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, Ar given in /in/Rh7kg:37 Stack trace: #0 /in/Rh7kg(37): array_values(Object(Ar)) #1 {main} thrown in /in/Rh7kg on line 37
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: array_values() expects parameter 1 to be array, object given in /in/Rh7kg on line 37 NULL

preferences:
186.15 ms | 402 KiB | 173 Q