How can an object be destroyed in PHP when leaving a page to trigger the destructor?

When leaving a page in PHP, objects are not automatically destroyed, so their destructors may not be triggered. To ensure that an object is properly destroyed and its destructor is called when leaving a page, you can use the `unset()` function to unset the object variable.

class MyClass {
    public function __destruct() {
        echo 'Object destroyed';
    }
}

$myObject = new MyClass();

// Perform actions

unset($myObject); // This will trigger the destructor and destroy the object