What are some best practices for accessing object arrays in classes in PHP?

When accessing object arrays in classes in PHP, it is best practice to use the arrow operator (->) to access object properties and methods. This ensures that you are properly accessing the elements within the object array and adhering to object-oriented principles.

class MyClass {
    private $data = [];

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

    public function getData($key) {
        return $this->data[$key];
    }
}

$obj = new MyClass();
$obj->setData('name', 'John Doe');
echo $obj->getData('name');