3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value): void { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset): bool { return isset($this->container[$offset]); } public function offsetUnset($offset): void { unset($this->container[$offset]); } public function offsetGet($offset): mixed { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new Obj; $obj[] = 3; $obj[] = 4; print_r($obj);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Obj Object ( [container:Obj:private] => Array ( [one] => 1 [two] => 2 [three] => 3 [0] => 3 [1] => 4 ) )

preferences:
99.16 ms | 402 KiB | 89 Q