|
-
March 28th, 2009, 11:15 PM
#1
Constructor and Desctructors in PHP? Do I need to delete/clean stuff? [PHP5]
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)
Code:
{
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:
Code:
$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,
-
March 30th, 2009, 08:54 AM
#2
Re: Constructor and Desctructors in PHP? Do I need to delete/clean stuff? [PHP5]
Rather than re-write the whole article for you...take a look at this.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|