class MyDestructableClass {
function __construct() {
print "\nIn constructor\n";
$this->name = "MyDestructableClass";
}
function __destruct() {
print "\nDestroying " . $this->name . "\n";
}
}
$obj = new MyDestructableClass();
當上面的腳本是在複雜環境下,__destruct
不會被調用時exit
,但我不能複製easily.Have有人注意過這個?什麼時候__destruct不會在PHP中被調用?
編輯
我會在這裏張貼整個的東西,這是symfony中的測試環境,這意味着你可以很容易地複製它,如果您熟悉的框架:
require_once dirname(__FILE__).'/../bootstrap/Doctrine.php';
$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);
$t = new lime_test(0, new lime_output_color());
class MyDestructableClass {
function __construct() {
print "\nIn constructor\n";
$this->name = "MyDestructableClass";
}
function __destruct() {
print "\nDestroying " . $this->name . "\n";
}
}
$obj = new MyDestructableClass();
$news = new News();
$news->setUrl('http://test');
$news->setHash('http://test');
$news->setTitle('http://test');
$news->setSummarize('http://test');
$news->setAccountId(1);
$news->setCategoryId(1);
$news->setThumbnail('http://test');
$news->setCreatedAt(date('Y-m-d H:i:s',time()));
$news->setUpdatedAt(date('Y-m-d H:i:s',time()));
$news->save();
exit();
與您的問題無關,但$ this-> name是不必要的 - 而是使用特殊常量'__CLASS__' – 2010-03-05 06:59:43
或get_class($ this); – Beachhouse 2015-01-29 16:17:16