PHP Destructor

Last Updated: July 31, 2021

This is a special method with name __destruct and this method is called when the object is released from the memory.

class Product {

  public function __destruct() {
    echo "Destructor is called";

You can not pass parameters to the destructor.

This is very useful when you do file operations and database operations. Because when the objects are released you can release the files connections and database connections