Array passed into class constructor is empty – Cannot access empty property

I am trying to pass in an array into my new class so that I always have access to the variable.

To do this:

class AppointmentData {

  private $date = [];

  public function __construct(Array $date)
    $this->date = $date;

  public function foo()



$appointmentData = new AppointmentData($date);

However when calling the function from my controller I get this error:

Cannot access empty property

Am I doing this correctly in assigning the variable in the constructor etc?

Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.