Constructor and Destructor in PHP

Example of constructor and destructor in PHP. Pretty simple syntax. Two preceding underscores.

class MyDestructableClass {
   function __construct() {
       print "In constructor\n";
       $this->name = "MyDestructableClass";

   function __destruct() {
       print "Destroying " . $this->name . "\n";

$obj = new MyDestructableClass();

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: