A destructor is called when the object is destructed or the script is stopped or exited.
If you create a __destruct() function, PHP will automatically call this function at the end of the script.
Notice that the destruct function starts with two underscores (__)!
<?php
class Student {
// Properties
var $name;
var $country;
// Methods
function __construct($name, $country) {
$this->name = $name;
$this->country = $country;
}
function __destruct() {
echo "Student name is {$this->name} and the country is {$this->country}";
}
}
$student = new Student("dilip", "india");
?>