3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Obj implements ArrayAccess { public $container = [ "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; takesArray($obj); function takesArray(array $arr) {}
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught TypeError: takesArray(): Argument #1 ($arr) must be of type array, Obj given, called in /in/csROV on line 32 and defined in /in/csROV:34 Stack trace: #0 /in/csROV(32): takesArray(Object(Obj)) #1 {main} thrown in /in/csROV on line 34
Process exited with code 255.

preferences:
56.66 ms | 873 KiB | 4 Q