3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyThing implements \ArrayAccess { protected $storage = []; public function __construct($values = array()) { foreach ($values as $name => $value) { $this->offsetSet($name, $value); } } public function offsetGet($name) { if (isset($this->storage[$name])) { return $this->storage[$name]; } } public function offsetSet($name, $value) { $this->storage[$name] = $value; } public function offsetUnset($name) { unset($this->storage[$name]); } public function offsetExists($name) { return isset($this->storage[$name]); } } function printArray(array $a) { print_r($a); } $thing = new MyThing(['foo' => 'bar']); printArray($thing);

preferences:
36.15 ms | 402 KiB | 5 Q