Ne zaman __ PHP çağrılacak değil yok edecek?

3 Cevap php
class MyDestructableClass {
   function __construct() {
       print "\nIn constructor\n";
       $this->name = "MyDestructableClass";
   }

   function __destruct() {
       print "\nDestroying " . $this->name . "\n";
   }
}

$obj = new MyDestructableClass();

Yukarıdaki komut bir complex ortamında olduğunda, __destruct zaman exit denilen almazsınız, ama ben hiç birini easily.Have yeniden olamaz bu fark?

EDIT

Ben burada bütün şeyler göndeririz, bu çerçevede bildik olup olmadığını kolayca üretebileceği anlamına gelir, Symfony test ortamı bulunuyor:

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();

3 Cevap

__ Imha denilen olmayacak:

  • "Çıkış" bir başka yıkıcı çağrılırsa
  • PHP Sürüm bağlı olarak: "çıkış" a "register_shutdown_function" fonksiyonu çağrılırsa
  • Bir ölümcül hata kodunda bir yerde varsa
  • Başka yıkıcı atılmış bir istisna varsa
  • Bir yıkıcı bir istisna (PHP> = 5.3.0) KOLU çalışırsanız

Şu ben şu anda aklınıza gelebilecek tüm sanırım

& Ne Pascal MARTIN dedi. Bu hata ayıklama ilk adımı bu.

Ekranda bir çıkışa sahip değil yıkıcı olarak değil anlamına gelmez: ouptut (maybe lime does that, to be able to work on it ? ) output_buffering kullanılarak çekilen ve komut örneğin, bittiğinde yankılandı değil olabilir.

For testing purposes, you could try writing to a file, in your __destruct method, instead of just echoing some text.
(Just make sure your application / PHP has the required privileges to write to your destination file)

(I've already run into situations where I would not see the output made in a destructor -- but it was actually called)

Doktrini ile aşina olmayan, ama bir kontrol noktası: _ construct()/ _destruct () onlar ölümcül hataları üretebilir olası durumlar için kontrol edin.