3v4l.org

run code in 500+ PHP versions simultaneously
<?php class AATest implements ArrayAccess { protected $array = array(); // ArrayAccess interface public function offsetExists($offset) { return key_exists($offset, $this->array); } public function offsetGet($offset) { return $this->array[$offset]; } public function offsetSet($offset, $value) { if( is_null($offset) ) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetUnset($offset) { unset($this->array[$offset]); } // debug public function dbgGetArray() { return $this->array; } } $object = new AATest(); $object[] = 'a'; $object[NULL] = 'b'; $object[] = 'c'; var_dump($object->dbgGetArray()); $array = array(); $array[] = 'a'; $array[NULL] = 'b'; $array[] = 'c'; var_dump($array);
Output for 8.5.0 - 8.5.9
Deprecated: Return type of AATest::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/OC9qQ on line 7 Deprecated: Return type of AATest::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/OC9qQ on line 10 Deprecated: Return type of AATest::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/OC9qQ on line 13 Deprecated: Return type of AATest::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/OC9qQ on line 20 array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } Deprecated: Using null as an array offset is deprecated, use an empty string instead in /in/OC9qQ on line 39 array(3) { [0]=> string(1) "a" [""]=> string(1) "b" [1]=> string(1) "c" }
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.32, 8.3.0 - 8.3.33, 8.4.1 - 8.4.24
Deprecated: Return type of AATest::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/OC9qQ on line 7 Deprecated: Return type of AATest::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/OC9qQ on line 10 Deprecated: Return type of AATest::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/OC9qQ on line 13 Deprecated: Return type of AATest::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/OC9qQ on line 20 array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } array(3) { [0]=> string(1) "a" [""]=> string(1) "b" [1]=> string(1) "c" }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 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.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } array(3) { [0]=> string(1) "a" [""]=> string(1) "b" [1]=> string(1) "c" }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/OC9qQ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/OC9qQ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/OC9qQ on line 3
Process exited with code 255.

preferences:
116.65 ms | 2945 KiB | 4 Q