doutui2883 2013-11-05 18:40 采纳率: 100%
浏览 30
已采纳

PHP OOP:从继承自父属性的子/子访问父属性

so the code is : DAO class

    abstract class DAO  
    {   
    protected $db; 
    protected $SQL_host='localhost';
    protected $SQL_port='3306';
    protected $SQL_dbname='projet'; 
    protected $SQL_login='root'; 
    protected $SQL_password='';

    protected function __construct()
    {
        $this->setDb(new PDO('mysql:host='.$this->SQL_host.';port='.$this->SQL_port.';dbname='.$this->SQL_dbname, $this->SQL_login, $this->SQL_password)) ;
    }

    protected function setDb(PDO $bdd)
    {
        $this->db = $bdd ;
    }


    }

and child UserDAO class

     class UserDAO extends DAO 
     {
     public function __construct()
     {
         parent::__construct();
     }
     }

When UserDAO child class inherits from parent DAO, does the child get parent's attributes ? If not, how can I make so ?

I've been looking around and they mostly tell to use get function but that's really not what i'm trying to do. Thanks for your help

  • 写回答

2条回答 默认 最新

  • dongyun8891 2013-11-05 18:46
    关注

    Yes, the subclass inherits the parent class's members.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!