Q:

PHP OOP Is it a good practice to close connection like this

this is my DataBase Class
class DataBase{
  public $_localhost  = "localhost";// server name => usually is localhost
  public $_user       = "root"; // username for the database
  public $_password   = "123"; // password for the database
  public $_dbname     = "ecommerce"; // database name
  public $db          = false;

  public  function __construct(){
    try{
      $this->db = new PDO("mysql:host=".$this->_localhost.";dbname=".$this->_dbname,$this->_user,$this->_password);
      $this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
      $this->db->exec("SET NAMES utf8");
      return $this->db;
    }catch(PDOException $e){
      echo $e->getMessage();
    }
  }

  public function __destruct(){
    $this->db = null;
  }
}

Now in my Application Class
class Application{
  public $db;

  public function __construct(){
    $this->db =  new DataBase();
    $this->db = $this->db->db;
  }
}

As i want to use my destruct function to close my connection 
Is that a good way to do this ?

A:

You do not need to close the database connection in a typical php flow. The PHP runtime will do that itself once the response was returned and all references to the object are unreachable.
In many web-situations you want persistent connections anyway as they reduce the overhead of opening and closing a connection each time a request is sent to your site.
Check the documentation for PDO::ATTR_PRESISTENT(Example 4) for that
However, you might want to close the database connection yourself in a long running non-web process if you know that the connection will idle for several minutes of hours.
Set the PDO object to null in that case to signal PHP that this specific connection may be closed.
The destructor is the wrong place for that. Add a custom close method to your class that does not depend on PHP Runtime calls.
Btw.:
It is considered bad practice to create an unnessesary hard coupling between your Application instance and the database connection(-wrapper). I would suggest you to change your application class to allow a constructor injection of your database instance. This might really help you with testing/mocking your code later and improves reusability.
If you want to read more about the general concept in php and an implementation example see this series of blog entries by Fabien Potencier

