PHP-编辑类以获得成功结果


PHP - Edit classes for success result

如何从3个类和1个扩展类中获取php数据ABCD结果。有人能帮我修一下代码吗?

class Common{
     public function __construct(){
          $this->data = 'A';
     }
     public function getData(){
          return $data;
     }
}
class SetOne extends Common{
     protected $data;
     public function __construct(){
          $this->data = 'B';
     }
}
class SetTwo extends Common{
     protected $data;
     public function __construct(){
          $this->data .= 'C';
          $obj = new SetOne();
     }
}
class SetTree extends Common{
     protected $data;
     public function __construct(){
          $this->data .= 'D';
          $obj = new SetTwo();
     }
}
$obj = new SetTree();
echo $obj->getData(); // I want to get the result: **ABCD**

我真的不知道怎么做-(感谢您的帮助。

一种解决方案是

class Common{
    protected $data;
    public function __construct(){
         $this->data = 'A';
    }
    public function getData(){
        return $this->data;
    }
}
class SetOne extends Common{
    public function __construct(){
        parent::__construct();
        $this->data .= 'B';
    }
}
class SetTwo extends SetOne{
    public function __construct(){
        parent::__construct();
        $this->data .= 'C';
    }
}
class SetTree extends SetTwo{
    public function __construct(){
        parent::__construct();
        $this->data .= 'D';
    }
}
$obj = new SetTree();
echo $obj->getData(); // I want to get the result: **ABCD**