PHP class constructor & destructor

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mohammad
Forum Newbie
Posts: 24
Joined: Tue Jul 26, 2005 5:31 am

PHP class constructor & destructor

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: PHP class constructor & destructor

Post 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.
Mohammad
Forum Newbie
Posts: 24
Joined: Tue Jul 26, 2005 5:31 am

Post by Mohammad »

Thanks for the clarification. thats why I say to everyone PHP rocks!!

Regards,
Mohammad
Post Reply