How can the ArrayAccess interface be utilized to handle unknown properties in PHP?

When dealing with unknown properties in PHP, the ArrayAccess interface can be utilized to handle them by implementing the required methods to access, set, unset, and check for the existence of properties as if they were elements of an array.

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

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

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

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

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

$customObj = new CustomObject();
$customObj['unknownProperty'] = 'some value';
echo $customObj['unknownProperty']; // Output: some value