title: Should a constructor do more than just create an instance?
body: <p>Trying to understand and use OOP in PHP I have  a class called <code>dbcon</code>. I am following a tutorial in youtube which is using the protected <code>connect()</code> function to connect to db. Now my question is why not connect to db in the constructor?</p>
  
  <pre><code>function __construct() {
        $this-&gt;DBSERVER  = "localhost" 
        $this-&gt;DBUSERNAME = "root" 
        $this-&gt;DBPASSWORD = "" 
        $this-&gt;DBNAME    = "thedb" 
  
        $conn = new mysqli($this-&gt;DBSERVER, $this-&gt;DBUSERNAME, $this-&gt;DBPASSWORD, $this-&gt;DBNAME);
        if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
        }     
        return $conn;
      } 
      }
  </code></pre>
  
  <p>can someone let me know what is the benefit or downside of this?</p>
  
  <pre><code>&lt;?PHP
  class dbcon {
      private $DBSERVER;
      private $DBUSERNAME;
      private $DBPASSWORD;
      private $DBNAME;
  
      protected function connect(){
        $this-&gt;DBSERVER   = "localhost" 
        $this-&gt;DBUSERNAME = "root" 
        $this-&gt;DBPASSWORD = "" 
        $this-&gt;DBNAME     = "thedb" 
  
        $conn = new mysqli($this-&gt;DBSERVER, $this-&gt;DBUSERNAME, $this-&gt;DBPASSWORD, $this-&gt;DBNAME);
        if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
        }     
        return $conn;
      }
  }
  ?&gt;
  </code></pre>