Kurucusuna sonsuz atma

3 Cevap

Ne bu böyle giderse bir php script olur?

class FooException extends Exception
{

    public function __construct() {
        throw new FooException;
    }
}

Muhtemelen aynı bulunuyor

while (TRUE) {
    new Exception();
}

Yürütme zamanı aşıldı, ya da bazı ölümcül hata ile başarısız olduğunda sadece çıkışları zaman aşımına?

3 Cevap

Eğer istisna inşa asla çünkü ilk durumda hiçbir şey olmuyor.

Sadece sıradan bir sonsuz bir döngü böylece ikinci durumda istisnası atılır.

Eğer sonunda bu satırı ekleyerek ilk örneğini değiştirmeniz Ancak eğer:

throw new FooException();

Sonunda tüm bellek tüketir, sonsuz bir döngüye neden olur:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes)

Ben (sonunda bir new FooException(); ekleyerek) PHP 5.2.8 denedim ve bellek bitti:

Ölümcül hata: tükenmiş 134217728 bayt İzin bellek boyutu 5. satırdaki (40 bayt ayırmaya çalıştı)

Sadece bunu test edebilir, ama bir istisna ve bir istisna zaten atılmış zaman ölümcül bir hata atıyor düşünüyorum.

EDIT: Tamam, ben karıştı. Sen bir out-of-bellek ölümcül hatayı buraya alıyorum:

class FooException extends Exception
{

    public function __construct() {
        throw new FooException;
    }
}

throw new FooException();

Eğer bir özel durum işleyici bir özel durum ne ben tarif olur.