PHP property as object

前端 未结 4 1901
感情败类
感情败类 2021-01-07 01:44

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         


        
4条回答
  •  走了就别回头了
    2021-01-07 02:46

    You cannot declare them in the property declarations, but you can instantiate them in the constructor __construct() The array() can be instantiated in the public $w without the new keyword: public $w = array();

    public function __construct()
    {
      $this->y = new ErrorVO();
    }
    

提交回复
热议问题