title: PHP: Extend custom database class with the default MySQLi class and a Singleton
body: <p>Lets say i have a singleton class with the sole purpose of creating singletons:</p>
  <pre><code>class singleton {
      public static function getInstance() {
      static $instance = null;
          if($instance === null) {
          $instance = new self;
          }
      return $instance;
      }
  }
  </code></pre>
  <p>And a custom database class extending the default one:</p>
  <pre><code>class database extends mysqli {
  // obvious stuff
  }
  </code></pre>
  <p>I now want to be able to have the database class being a children of both, the singleton (for the singleton creation) and the mysqli-class. Basically something like:</p>
  <pre><code>class database extends singleton {}
  class database extends mysqli {}
  </code></pre>
  <p>According to my research, this is not possible in PHP.</p>
  <p>What I'm trying to achieve is, having another method called getInstance() in the database class (so, this method is present in the classes &quot;database&quot; and &quot;singleton&quot;, which then first calls the parent constructer (that creates the singleton) and then returns to the child to continue with custom stuff for the corresponding class. Like this:</p>
  <pre><code>class singleton {
      public static function getInstance() {
      static $instance = null;
          if($instance === null) {
          $instance = new self;
          }
      return $instance;
      }
  }
  
  class database extends singleton {}
  class database extends mysqli {
      public static function getInstance() {
      $instance = parent::getInstance();
      
      // Custom code
      
      return $instance;
      }
  }
  </code></pre>
  <p>Is that somehow possible? I thought about traits, but you cannot call them as parents.</p>