1

I don't understand why

class test {
 
    
    function __destruct() {
        echo "I am the destructor<br>";
    }
    
    function __construct() {
         $this->a=debug_backtrace(); # <=== THIS LINE
    }
}
$myclass=new test();
unset($myclass);
echo "Last Line<br>";

out- and incommenting this line changes the order of the echo output. Why is the destructor not called by the unset() when the contsructor did a debug_backtrace() before?

user3636110
  • 166
  • 11
  • PHP uses garbage collection for memory management and the [destructor](https://www.php.net/manual/en/language.oop5.decon.php) "will be called as soon as there are no other references to a particular object". Thus I reckon that PHP calls destructors as it sees fit and it isn't something you can control. – Álvaro González Jun 24 '20 at 09:54

0 Answers0