tags:

views:

149

answers:

1

Is it a good practice to unset the variables that you used in a class? Or its an optional? If its a good practice what is the benefit of using the unset function? Thank you.

+5  A: 

You really don't need to worry about cleaning up your variable declarations in PHP, it's garbage collection takes care of all of that for you. Your __destruct() methods are primarily for things like closing persistent connections.

Cryo
Okay thank you for your help. In short __destruct() in php often use to close mysql connection? Is this correct?
Actually PHP now properly handles closing MySQL connections as well, you don't need to worry about those either. Perhaps for compatability with older versions it wouldn't hurt to include it but __destruct wasn't added until PHP5 so I'm not even sure it matters. An example of when you would want to use __destruct is if you had an FTPConnection class that kept a persistent remote FTP connection open so you could send commands to it and it's __destruct would close the lingering connection gracefully. Hope that helps.
Cryo
Okay thanks for the big help. Thank you.