Classes and objects in PHP: destructors
PHP does not directly support destructors. However, you can easily simulate a destructor by calling the PHP function unset. This function deletes the content of a variable and returns this free memory space to the system. Function unset works with objects the same way as with variables. Suppose you're working with an object $Design. After you've finished working with this particular object the function is called:
This command deletes all the memory content of $Design. In the spirit of encapsulation, you can place the call of unset into the method named destroy() and then call it:
Usually the destructor is called only when working with objects that use a lot of resources, because all the variables and objects are automatically destroyed at the end of the script.