🐘 PHP
Intermediate
What is the ArrayAccess interface in PHP?
Answer
The ArrayAccess interface allows objects to be accessed using array notation ($object["key"]). Implement four methods: offsetExists($offset) (called by isset($obj[$key])), offsetGet($offset) (called by $obj[$key]), offsetSet($offset, $value) (called by $obj[$key] = $val), and offsetUnset($offset) (called by unset($obj[$key])). This is used by Laravel's Collections, Symfony's ParameterBag, and many ORMs so their objects behave like arrays. It enables a uniform interface where consuming code does not need to know if it is working with a plain array or a complex object — both support the same [] access syntax.