Is it possible to set a property of a class as a object?
Like:
class User {
public $x = \"\";
public $y = new ErrorVO();
public $w = new
In the constructor, yes.
class User
{
public $x = "";
public $y = null;
public $w = array();
public function __construct()
{
$this->y = new ErrorVO();
}
}
Edit
KingCrunch made a good point: You should not hard-code your dependencies. You should inject them to your objects (Inversion of Control (IoC)).
class User
{
public $x = "";
public $y = null;
public $w = array();
public function __construct(ErrorVO $y)
{
$this->y = $y;
}
}
new User(new ErrorVD());