3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @template-implements ArrayAccess<int, string> */ class C implements ArrayAccess { /** * @param int $offset * @return bool */ public function offsetExists($offset) { return true; } /** * @param int $offset * @return string */ public function offsetGet($offset) { return "";} /** * @param ?int $offset * @return void */ public function offsetSet($offset, $value) { /** @psalm-suppress ForbiddenCode */ var_dump(__METHOD__, array("offset" => $offset, "value" => $value)); } /** * @param int $offset * @return void */ public function offsetUnset($offset) { } } $q = new C; $q[] = '123'; // should only be forbidden when offsetSet does not accept null as its first parameter

preferences:
117.74 ms | 2739 KiB | 5 Q