title: Working with extended classes in PHP
body: <p>I have 2 classes looking like this:</p>
  
  <pre><code>class db {
  
      protected $db;
  
      function __construct() {
          $this-&gt;connect();
      }
  
      protected function connect() {
          $this-&gt;db = new MySQLi(db_host, db_user, db_pass, db_name) or die($this-&gt;db-&gt;error);
          $this-&gt;db-&gt;set_charset('utf8');
      }
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class sample extends db {
  
      protected $js_base_dir;
  
      public function __construct($js_base_dir = js_dir) {
          $this-&gt;js_base_dir = $js_base_dir . "/";
      }
   ....
  </code></pre>
  
  <p>I want to use $this->db inside second class, but <code>__construct</code> in <code>sample</code> class overrides first classes construct function. How to get $this-> db inside second class? Am I doung something wrong? if yes what's proper way? </p>