What potential issues can arise when accessing arrays within a PHP class?

One potential issue when accessing arrays within a PHP class is that you may encounter scope issues if the array is not declared as a class property. To solve this, you can declare the array as a class property by using the "public" or "private" keyword before the array declaration within the class.

class MyClass {
    public $myArray = [];

    public function addToMyArray($value) {
        $this->myArray[] = $value;
    }

    public function printMyArray() {
        print_r($this->myArray);
    }
}

$myObject = new MyClass();
$myObject->addToMyArray("Hello");
$myObject->addToMyArray("World");
$myObject->printMyArray();