Shaitan00
March 28th, 2009, 11:15 PM
I've created some PHP classes that, in the constructor, create an instance (object) of another PHP class (for example a database), does this need to be cleaned up somehow? For example is there such a thing as a destructor [function() ~function()] in PHP5 and is it needed?
For example - check out the following code I have for a class called Tools.class.php (for example)
{
private $db = NULL; // Database Interface
////////////////////////////////////////////////////////////////////////////
// Constructor
function Tools()
{
$this->db = new Database();
}
function DoStuff()
{
... do stuff ...
}
So, in the constructor of tools I create an instance of Datbase ($db), and then in DoStuff() I use that connection to get/set data from the Database ... All this is great but what happens when Tools is no longer of any use? Meaning I have a PHP file that does:
$tool = new tools();
$tool->DoStuff();
But that is it ... Do I need to delete $tool somehow?
And within Tools.class.php do I need to somehow cleanup $db?
I don't want to cause any memory leak or Database connection issues.
Any help would be much apprecited.
Thanks,
For example - check out the following code I have for a class called Tools.class.php (for example)
{
private $db = NULL; // Database Interface
////////////////////////////////////////////////////////////////////////////
// Constructor
function Tools()
{
$this->db = new Database();
}
function DoStuff()
{
... do stuff ...
}
So, in the constructor of tools I create an instance of Datbase ($db), and then in DoStuff() I use that connection to get/set data from the Database ... All this is great but what happens when Tools is no longer of any use? Meaning I have a PHP file that does:
$tool = new tools();
$tool->DoStuff();
But that is it ... Do I need to delete $tool somehow?
And within Tools.class.php do I need to somehow cleanup $db?
I don't want to cause any memory leak or Database connection issues.
Any help would be much apprecited.
Thanks,