Destructor + unset | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Destructor + unset

There is a remark "To explicitly trigger the destructor, you can destroy the object using the unset() function in a statement similar to: unset($p);" 1) How is it connected with the destructor? 2) Should we use __destruct + unset? 3) Why don't people put unset function inside the constructor?

8th Jun 2019, 5:23 PM
Maksym Biliaievskyi
Maksym Biliaievskyi - avatar
1 Answer
0
We can set values and functions, with constructor when an object created... and sometimes we need to do something on unset an object, like disconnect database connection, So we use destructor. 1 & 2) destructor run when we unset($object); 3) because it is not Standard! I wrote that top👆...
3rd Sep 2020, 8:07 PM
Amin Maleki
Amin Maleki - avatar