snehoozle
snehoozle

Reputation: 273

PHP SplObjectStorage Cannot create within a class

Would it be possible to initialize a protected SplObjectStorage as a map within a class? I seem to be running into an error whenever I try this. Similar to example below:

class a {

  protected $a = new SplObjectStorage();

  ...

}

Upvotes: 0

Views: 139

Answers (1)

Alon Eitan
Alon Eitan

Reputation: 12025

you need to use constructor

class a {
  public function __construct() {
     $this->a = new SplObjectStorage();
  }

  protected $a;

  ...
}

Upvotes: 0

Related Questions