PHP - extended __construct

后端 未结 3 956
广开言路
广开言路 2021-01-31 08:09

I was wondering if you could help me out..

I have two classes, one extends the other.. Class B will be extended by various different objects and used for common databas

3条回答
  •  臣服心动
    2021-01-31 08:53

    Call parent::__construct() in a::__construct():

    class a extends b
    {
       public function __construct()
       {
           parent::__construct();
       }   
    
       public function validateStuff()
       {
          $this->insert_record();
       }
    }
    

    You can omit a's constructor altogether if you're not doing any a-specific stuff.

提交回复
热议问题