Constructors and Destructors in PHP

19 Nov

PHP 5.3.3 allows us to declare “Constructors” and “Destructors” in a new way. Before this, method with the same name with-in a class treated as “Constructor”. But now we declare constructor as :

__construct() {

// Generally used for initializing the variables


And we declare destructor as :

__destruct() {

//Generally used to release memory or make free the resources


“Constructor” called on each newly created object and “Destructor” called when the object is explicitly destroyed or in any order in shutdown sequence.

Leave a comment

Posted by on November 19, 2010 in PHP


Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: