A Destructor in PHP is a special function that runs automatically when an object is destroyed or the script ends.
It is used to clean up resources.
<?php
class Car {
function __destruct() {
echo "Car object destroyed";
}
}
$car = new Car();
?>- __destruct() runs automatically
- It runs when the object is deleted or the program finishes.