constructor and destructor in php

Discuss about last tutorial.

Today we will learn about constructors and destructors. Before moving further we should know what are constructors and destructors ? Why we use constructor and destructor in php ?

Constructor are the special method which gets initialized (called) just after object initialization (creation). Similarly, destructors are its vice-versa.

Destructors are special method which is used to clean (free up memory) objects after its use.

Typically the destructors methods contains a cleaning code which free up memory of an object. Since these are rare in in php because php automatically cleans all resource of a page at the end of script.

Now we will focus why we use constructor and destructor. Learn through example.

 

Without Constructor Using Constructor

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *