Home / Articles / Programming languages / Scripting languages / PHP / Classes and objects in PHP: destructors

Classes and objects in PHP: destructors

Classes and objects in PHP: destructors
 
Classes and objects in PHP: destructors
  • Currently 0 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 0/5 (0 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


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:

unset($Design);

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:

$Website->destroy();

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.


 

Read also

What is PHP?

What is PHP?

Classes and objects in PHP

Classes and objects in PHP

How to access classes and objects in PHP

How to access classes and objects in PHP

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation