How can the issue of array access be effectively resolved when working with wrapper classes in PHP?

When working with wrapper classes in PHP, the issue of array access can be effectively resolved by implementing the ArrayAccess interface in the wrapper class. This interface requires the implementation of offsetExists, offsetGet, offsetSet, and offsetUnset methods which allow the wrapper class to behave like an array.

class Wrapper implements ArrayAccess {
    private $data = [];

    public function offsetExists($offset) {
        return isset($this->data[$offset]);
    }

    public function offsetGet($offset) {
        return $this->data[$offset];
    }

    public function offsetSet($offset, $value) {
        $this->data[$offset] = $value;
    }

    public function offsetUnset($offset) {
        unset($this->data[$offset]);
    }
}

$wrapper = new Wrapper();
$wrapper['key'] = 'value';
echo $wrapper['key']; // Output: value