Page 1 of 1

PHP class constructor & destructor

Posted: Mon Mar 06, 2006 7:34 am
by Mohammad
Hello

Its not very clear to me, if we have defined a class, and while in the program which we have written, we declare several object from that class, is there any need for us to call a destructor wheneve our job is done with that object and is no longer needed!

I mean what happens if we dont define any destructor method? will it consume memory?

I would be thankful if someone can explain this to me....

Thanks in advance

Re: PHP class constructor & destructor

Posted: Mon Mar 06, 2006 7:38 am
by Chris Corbyn
Mohammad wrote:Hello

Its not very clear to me, if we have defined a class, and while in the program which we have written, we declare several object from that class, is there any need for us to call a destructor wheneve our job is done with that object and is no longer needed!

I mean what happens if we dont define any destructor method? will it consume memory?

I would be thankful if someone can explain this to me....

Thanks in advance
A destructor is rarely needed.... it's mostly for cleaning up in a large object. I wouldn't worry about it, you'll know when you need to use one (if ever). The memory consumed isn't really even worth taking about... PHP handles memory quite well without having to make too many considerations during development unlike languages like C.

Posted: Mon Mar 06, 2006 11:20 pm
by Mohammad
Thanks for the clarification. thats why I say to everyone PHP rocks!!

Regards,
Mohammad