0

I get the following error Creating default object from empty value... each time I attempt to add a nested object.

class api {

    private $authentication=null;
    private $status=null;
    private $response=null;

    public function __construct($user, $token) {
        $this->status->version=2.3; 
        $this->authentication->user=$user;
        $this->authentication->token=$token;
    }

}

How can I accomplish this exact thing without getting this error?

I don't want to use arrays for this particular thing.

Nikk
  • 7,384
  • 8
  • 44
  • 90

1 Answers1

0

does this help you or am I misunderstanding...

public function __construct($user, $token) {
    $this->status = new stdClass(); // Here
    $this->status->version=2.3; 
    $this->authentication = new stdClass(); // & Here
    $this->authentication->user=$user;
    $this->authentication->token=$token;
}
Simon K
  • 1,503
  • 1
  • 8
  • 10