3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); use function PHPStan\dumpType; use function PHPStan\Testing\assertType; class Obj implements ArrayAccess { private $container = [ ]; 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; } } $o = new Obj(); var_dump(is_iterable($o)); var_dump(is_array($o)); var_dump($o instanceof Traversable); foreach($o as $k => $v) { var_dump($k, $v); }

preferences:
31.11 ms | 405 KiB | 5 Q