Destructor in PHP is used to deleted or remove object of class. It is automatically called by PHP when script is about to end.
__destruct Function
To add Destructor in class, PHP provides __destruct function, it does not accepts any arguments.
Syntax
function __destruct(){
}
Example
<?php
class Mobile{
// Properties
public $company;
// constructor
function __construct($company) {
$this->company = $company;
}
// destructor
function __destruct($company) {
$this->company = $company;
}
}
Mobile myPhone = new Mobile("Motorola");
?>