PHP Destructor
__destruct() function рддрдм рдХрд▓ рд╣реБрдиреНрдЫ рдЬрдм object рдХреЛ destruction рд╣реБрдиреНрдЫ рд╡рд╛ script рдмрдиреНрдж рд╣реБрдиреНрдЫ рд╡рд╛ exit рд╣реБрдиреНрдЫред
рдпрджрд┐ рддрдкрд╛рдИрдБрд▓реЗ __destruct() function рдмрдирд╛рдЙрдиреБрднрдпреЛ рднрдиреЗ, PHP рд▓реЗ script рдХреЛ рдЕрдиреНрддреНрдпрдорд╛ рдпрд╕рд▓рд╛рдИ рд╕реНрд╡рддрдГ (automatically) рдХрд▓ рдЧрд░реНрдиреЗрдЫред
рдзреНрдпрд╛рди рджрд┐рдиреБрд╣реЛрд╕реН рдХрд┐ destruct function рджреБрдИрд╡рдЯрд╛ underscores (__) рдмрд╛рдЯ рд╕реБрд░реБ рд╣реБрдиреНрдЫ!
Example
<?php
class Fruit {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function __destruct() {
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
$apple = new Fruit("Apple", "Red");
?>
class Fruit {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function __destruct() {
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
$apple = new Fruit("Apple", "Red");
?>