In the object oriented programming have many magic method . Whose uses is different . According to requiremt we can use them different place . __desctruct() magic method one of them . in this tutorials we are going to learn about __desctruct() method
Syntax of __desctruct() method , Working of __desctruct() method . how to use __desctruct() method , when __desctruct() call . so lets start .
Syntax of __desctruct() method .
<?php
class dbmodel{
public function __destruct(){
/* write code here */
}
}
?>
__destruct method is opposite __construct method . __destruct method call automatically when then object of class work completly end then __destruct() method call automatically . __destruct never receive any type of parameter .
<?php
class dbmodel{
public $welcome = '';
public function __construct($welcome){
$this->welcome = $welcome;
echo $this->welcome."<br />";
}
public function insert(){
echo "you are inside in insert method . <br />";
}
public function __destruct(){
echo "this message inside destruct method !!! <br />";
}
}
$db_obj = new dbmodel("hello , welcome in jswebsolutions .");
$db_obj->insert();
?>
Output :
hello , welcome in jswebsolutions . you are inside in insert method . this message inside destruct method !!!