Is the use of __destruct redundant in this scenario?
Posted: Thu May 06, 2010 1:21 pm
I'll just use this stripped down version of my login data access layer class as an example. Now after instantiating the DB class i figured i'd destroy it when the Login_DAL class is destroyed. However when removing the __destruct the PHP garbage collector seems to destroy the DB object itself. So since PHP does this on it's own is it redundant to unset my objects? Or would it be wise to leave the destructor methods in and unset all references to instantiated objects manually for better programming practices? I'd like to hear what you guys do in your own applications.
Code: Select all
class Login_DAL
{
private $db = null;
function __construct()
{
$this->db = new DB();
}
public function addLogin($email, $password)
{
mysql_query("insert into login(email, Password) values('$email', '$password');");
return mysql_insert_id();
}
function __destruct()
{
unset($this->db);
}
}