class Person {
public static function ShowQualification() {
}
}
class School {
public static $Headmaster = new Person(); // NetBeans complains about this line
}
Why is this not possible?
I want to be able to use this like
School::Headmaster::ShowQualification();
..without instantiating any class. How can I do it?
Update: Okay I understood the WHY part. Can someone explain the HOW part? Thanks :)
From the docs,
new Person()
is not a literal or a constant, so this won't work.You can use a work-around:
new Person()
is an operation, not a value.http://php.net/static
You can initialise the School class to an object: