To better understand the __destrust method:
class A {
protected $id;
public function __construct($id)
{
$this->id = $id;
echo "construct {$this->id}\n";
}
public function __destruct()
{
echo "destruct {$this->id}\n";
}
}
$a = new A(1);
echo "-------------\n";
$aa = new A(2);
echo "=============\n";
The output content:
construct 1
-------------
construct 2
=============
destruct 2
destruct 1