Is there a way in PHP to destroy an object from within that same object?
Share
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.
There is a way to self destruct an object :
Use the
$GLOBALSarray to find your instance in it, then useunset(). Be aware thatunset()does not automatically call the__destruct()magic method all the time…There is such a note in this way (see the
unset()documentation) in the PHP documentation, but it does not explain exactly whenunset()does not call the__destruct()method.And I had this specific behaviour :
I do a :
And the
__constructoris called first, then the__destruct(). Or I would like the__destruct()to be called first becauseunset()is before clone…I ma stuck with that now…
Nicolas.