3v4l.org

run code in 300+ PHP versions simultaneously
<?php function needArray(ArrayAccess $arr) { $arr[] = 'hi'; return $arr; } class obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new obj; echo "testing with ArrayAccess\n"; var_dump(needArray($obj)); $arr = []; echo "testing with array\n"; var_dump(needArray($arr));
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of obj::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/FOEP0 on line 28 Deprecated: Return type of obj::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/FOEP0 on line 36 Deprecated: Return type of obj::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/FOEP0 on line 20 Deprecated: Return type of obj::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/FOEP0 on line 32 testing with ArrayAccess object(obj)#1 (1) { ["container":"obj":private]=> array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) [0]=> string(2) "hi" } } testing with array Fatal error: Uncaught TypeError: needArray(): Argument #1 ($arr) must be of type ArrayAccess, array given, called in /in/FOEP0 on line 49 and defined in /in/FOEP0:3 Stack trace: #0 /in/FOEP0(49): needArray(Array) #1 {main} thrown in /in/FOEP0 on line 3
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 obj::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/FOEP0 on line 28 Deprecated: Return type of obj::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/FOEP0 on line 36 Deprecated: Return type of obj::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/FOEP0 on line 20 Deprecated: Return type of obj::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/FOEP0 on line 32 testing with ArrayAccess object(obj)#1 (1) { ["container":"obj":private]=> array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) [0]=> string(2) "hi" } } testing with array Fatal error: Uncaught TypeError: needArray(): Argument #1 ($arr) must be of type ArrayAccess, array given, called in /in/FOEP0 on line 49 and defined in /in/FOEP0:3 Stack trace: #0 /in/FOEP0(49): needArray(Array) #1 {main} thrown in /in/FOEP0 on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.30
testing with ArrayAccess object(obj)#1 (1) { ["container":"obj":private]=> array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) [0]=> string(2) "hi" } } testing with array Fatal error: Uncaught TypeError: needArray(): Argument #1 ($arr) must be of type ArrayAccess, array given, called in /in/FOEP0 on line 49 and defined in /in/FOEP0:3 Stack trace: #0 /in/FOEP0(49): needArray(Array) #1 {main} thrown in /in/FOEP0 on line 3
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
testing with ArrayAccess object(obj)#1 (1) { ["container":"obj":private]=> array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) [0]=> string(2) "hi" } } testing with array Fatal error: Uncaught TypeError: Argument 1 passed to needArray() must implement interface ArrayAccess, array given, called in /in/FOEP0 on line 49 and defined in /in/FOEP0:3 Stack trace: #0 /in/FOEP0(49): needArray(Array) #1 {main} thrown in /in/FOEP0 on line 3
Process exited with code 255.

preferences:
175.14 ms | 402 KiB | 170 Q