3v4l.org

run code in 500+ PHP versions simultaneously
<?php class AATest implements ArrayAccess { protected $array = []; // ArrayAccess interface public function offsetExists(mixed $offset): bool { return key_exists($offset, $this->array); } public function offsetGet(mixed $offset): mixed { return $this->array[$offset]; } public function offsetSet(mixed $offset, mixed $value): void { if( is_null($offset) ) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetUnset(mixed $offset): void { 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[] = 'a'; $array[NULL] = 'b'; $array[] = 'c'; var_dump($array);
Output for 8.5.0 - 8.5.9
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/KIt91 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
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" }

preferences:
70.63 ms | 1051 KiB | 4 Q