Create a class immediately after the property field?

Possible duplicate:
declare a property as an object?

in java you can create an object immediately after the property field, for example:

but it doesn't seem to work for php:

class Test {
    public $object = new Object();
}

do you need to create it in __construct () and assign it to a property?

thank

+3
source share
1 answer

From php.net

This declaration may include initialization, but this initialization must be a constant value, that is, it must be able to be evaluated at compile time and should not depend on runtime information for evaluation.

, . ,

+2

Source: https://habr.com/ru/post/1742921/


All Articles