The following code produces a fatal error in PHP:
class A {}
class B {
private A $a = new A();
}
PHP Fatal error: Constant expression contains invalid operations
Of course, you can move this assignment into B's constructor, and then it will run. But why does PHP limit you to constant values in this context, when the analogous operation is allowed in e.g. Java?
My Answer:
you not sleep at night?
Rate this post
5 of 5 based on 7555 votesComments