PHP

How to call base class destructor from the derived class in PHP | PHP programs

How to call base class destructor from the derived class in PHP | PHP programs

How to call base class destructor from the derived class in PHP | PHP programs

We will call the destructor of the parent class from the destructor of the child class, here we need to use the parent keyword with :: (scope resolution operator).

<?php


class Base
{
    function __destruct()
    {
        echo "Base:destructor  called<br>";
    }
}

class Derived extends Base
{
    function __destruct()
    {
        echo "Derived:destructor  called<br>";
        parent::__destruct();
    }
}

$dObj = new Derived();
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community