PHP Basic Tutorial
MySQL Connection
PHP Advanced
A destructor is a special method in a class that is automatically called when an object is destroyed or goes out of scope.
In PHP, destructors are defined using the __destruct()
method.
class ClassName { public function __destruct() { // Code to be executed when the object is destroyed } }
The example below has a __construct() function that is automatically called when you create an object from a class, and a __destruct() function that is automatically called at the end of the script:
Try it yourself
Another example:
Try it yourself