title: Destructor method for static instance variable?
body: <p>This is my class:</p>
  
  <pre><code>class MySQLDB extends PDO{
  
          private $_connection;
          private static $_instance; //The single instance
          private $_host = MYSQL_SERVER_NAME;
          private $_username = MYSQL_SERVER_USERNAME;
          private $_password = MYSQL_SERVER_PASSWORD;
          private $_database = MYSQL_SERVER_DBNAME;
          /*
          Get an instance of the MySQLDB
          @return Instance
          */
          public static function getInstance() {
                  if(!self::$_instance) { // If no instance then make one
                          self::$_instance = new self();
                  }
                  return self::$_instance;
          }
  
          // Get PDO MySQL connection
          public function getConnection() {
                  return $this-&gt;_connection;
          }
  
      public function __construct(){
          try {
              $this-&gt;_connection = new PDO("mysql:host={$this-&gt;_host};dbname={$this-&gt;_database};charset=utf8", $this-&gt;_username, $this-&gt;_password);
              $this-&gt;_connection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              $this-&gt;_connection-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
          }
          catch(PDOException $e) {
              throw new Exception($e-&gt;getMessage());
          }
      }
  
      public function __destruct(){
          // unset($this-&gt;_connection);
          self::$_instance = null;
      }
  
  }
  </code></pre>
  
  <p>This is in my main:</p>
  
  <pre><code>$db = MySQLDB::getInstance();
  
  $db-&gt;__destruct();
  
  print_r($db).'&lt;br /&gt;&lt;br /&gt;';
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>MySQLDB Object ( [_host:MySQLDB:private] =&gt; localhost [_username:MySQLDB:private] =&gt; username [_password:MySQLDB:private] =&gt; [_database:MySQLDB:private] =&gt; dbname )
  </code></pre>
  
  <p>My question: Why do I get this output? If I'm calling the __destruct() method like above, shouldn't I get just an empty output - since I'm nulling the instance?</p>
  
  <p>Or maybe I should just use this in main:</p>
  
  <pre><code>$db = null;
  print_r($db).'&lt;br /&gt;&lt;br /&gt;';
  </code></pre>
  
  <p>How do I make sure I've closed the connection and killed the object?</p>