PHP OOP - Destructor
In PHP (Object-Oriented Programming), a destructor is a special method that is automatically called when an object is destroyed or goes out of scope. It's commonly used to perform cleanup operations such as closing database connections or releasing resources.
Syntax of Destructor in PHP
Key Points
-
The destructor method is named
__destruct()
. -
PHP automatically calls the destructor when:
-
The object is explicitly destroyed using
unset()
. -
The script ends and the object is no longer referenced.
-
-
Unlike constructors, destructors do not accept parameters.