0% found this document useful (0 votes)
12 views

Destructor

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Destructor

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Destructor:

 In Php Destructor function is defined by __destruct()


function.
 Destructor function is used to destruct or free the
allocated memory of an object.
 It automatically called when the object have done its work.
or,
Destructor function is the last called function in the
object's life.
syntax:
function __destruct()
{
//body of destructor
}
program:
<?php
class book
{
function __construct($bookname) //Parameterized
constructor
{
echo "Constructor function calling <br>";
$this->bookname=$bookname;
}
function get()
{
echo $this->bookname;
echo "<BR>";
}
function __destruct()
{
echo "Destructor function calling <br>";
}
}
$obj1=new book("JAVA");
$obj1->get();
?>
output:

Program:
<?php
class book
{
function __construct($bookname) //Parameterized
constructor
{
echo "Constructor function calling <br>";
$this->bookname=$bookname;
}
function get()
{
echo $this->bookname;
echo "<BR>";
}
function __destruct()
{
echo "Destructor function calling <br>";
}
}
$obj1=new book("JAVA");
$obj1->get();
$obj2=new book("PHP");
$obj2->get();
$obj3=new book("C++");
$obj3->get();
$obj1->get();
?>
output:

You might also like