<?php
class test{
public function __construct(){
var_dump("start test");
}
public function __destruct()
{
var_dump("end test");
}
}
class t {
static $test=null;
public static function tt(){
self::$test=new test();
return self::$test;
}
public static function tts(){
self::$test=null;
}
}
class test1{
static $instatn=null;
static $test1=null;
public function __construct(){
var_dump("start test1");
}
public static function instance()
{
if (empty(self::$instatn)){
self::$instatn=new static();
}
self::$test1= t::tt();
var_dump(self::$test1);
return self::$instatn;
}
public static function tt(){
}
public function tts(){
t::tts();
}
public function __destruct()
{
var_dump("end test1");
}
}
$t=test1::instance();
$t->tts();
unset($t);
sleep(5);
var_dump("------------------end sleep--------------------------");
the above code outputs
string(11) "start test1"
string(10) "start test"
object(test)-sharp2 (0) {
}
string(53) "------------------end sleep--------------------------"
string(9) "end test1"
string(8) "end test"
$t=test1::instance (); the test class
$t-> tts (); is created here, and the test class is destroyed. Shouldn"t the destructor of test be triggered immediately
Why is there no test destructor triggered? how can I trigger
?