I have a class with typed property object. I need to define default empty value for that property:
This doesn't work:
public object $doctor = new \stdClass();
Is this even possible?
This is impossible and the error you get (Constant expression contains invalid operations) explains why: in PHP the properties can only be initialized with constant expressions. You can't use any function calls, variables or an expression producing a new object instance like in your case.
See more details here: PHP Error : Fatal error: Constant expression contains invalid operations
As a workaround I'd suggest initializing the property in the constructor
__get(). Or possible check it and instantiate it when needed to use it.