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);

preferences:
83.84 ms | 1052 KiB | 5 Q