I'd like to create a class (e.g. Bar
) which has a private static property. This property should be an array of objects of Foo
.
<?php
class Foo {
}
class Bar {
private static $classes = array(new Foo(), new Foo());
public static function testClasses() {
var_dump(self:$classes);
}
}
Bar::testClasses();
However this code throws an exception:
PHP Parse error: syntax error, unexpected 'new' (T_NEW), expecting ')' in [...]/test.php on line 8
Can somebody explain me why this is not possible?