can you initialize a static array of objects in a class in PHP? Like you can do
class myclass {
public static $blah = array("test1", "test2", "test3");
}
but when I do
class myclass {
public static $blah2 = array(
&new myotherclass(),
&new myotherclass(),
&new myotherclass()
);
}
where myotherclass is defined right above myclass.
That throws an error however; is there a way to achieve it?
Nope. From http://php.net/manual/en/language.oop5.static.php:
I would initialize the property to
null, make it private with an accessor method, and have the accessor do the “real” initialization the first time it’s called. Here’s an example: