PHP DESTRUCTOR
- 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.
- The destructor method will be called as soon as all references to a particular object are removed.
- when the object is explicitly destroyed in any order in shutdown sequence.
- Used to de-initialize objects already existing to free up memory for new accommodation.
SYNTAX FOR DESTRUCTOR IN PHP :
class X { public: // Constructor for class X X(); // Destructor for class X ~X(); };
EXAMPLE FOR DESTRUCTOR IN PHP :
< ! DOCTYPE html>
<html>
<body>
<?php
class Fruit
{
public $name ;
publ
}
}
$apple = new Fruit ( "Apple" ) ;
?>
</body>
</html>
OUTPUT :
The fruit is Apple.