Possible Duplicate:
Should I use unset in php __destruct()?
Is it a good idea to unset($this) in class destruct and what difference it will make ?
function __destruct(){
unset($this);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$thisis a special variable in PHP – that special, it’s pseudo. I wonder if you could unset it at all from within a class/object context, maybe in earlier PHP versions, but then you should consider it a flaw.Do not do that. Unset the object pointer (that is from the outside), and garbage collection takes care on it’s own.
The
__destructfunction is for unsetting such “outer” object pointers that are actually internal to the$thisobject, like if you use aggregation and composition.Especially with circular references, it might help the PHP garbage collector to do the job more efficiently. But this does not depend on
$thisbut what the object actually carries which means it highly depend on concrete code.Are you running into an actual memory issue you have the feeling the garbage collector can not deal with? Only if you can answer that with Yes, you normally need to think about
__destruct.