in java you can create an object directly after the property field like this:
but it seems not working for php:
class Test {
public $object = new Object();
}
you have to create it in the __construct() and assign it to the property?
thanks
in java you can create an object directly after the property field like this:
but it seems not working for php:
class Test {
public $object = new Object();
}
you have to create it in the __construct() and assign it to the property?
thanks
From php.net
This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.
So no, you cant initialize it to an object. You'll have to do it in the constructor like you said