Ben aşağıdaki kurulum varsa PHP5 bir __ imha () fonksiyonu çağırarak değil bulundu:
class test { __destruct() { echo 'hehe'; exit; } } header('Location: http://test.com/'); exit;
Bu imha işlevini çağırır asla
destructor denir:
Yönlendirmek için bir başlık kullanarak çağrıldığını gelen yıkıcı engellemez.
Also note that the destructor is called PHP script sonunda -- but doesn't prevent the redirection, as the header saying "redirect" has already been generated.
Örneğin, bu kod ile:
class Test {
public function __destruct() {
echo 'hehe';
file_put_contents('/tmp/test-desctructor.txt', "glop\n");
exit;
}
}
$a = new Test();
header('Location: http://example.com/');
exit;
(Note that I corrected a few mistakes, and added an actual instanciation of the class)
Sen çıkışta "hehe
" görmezsiniz, ancak dosya /tmp/test-desctructor.txt
yaratılmış olduğunu göreceksiniz:
$ cat /tmp/test-desctructor.txt
glop
Eğer çıktıda üzerinde "hehe
" almak istiyorsanız yönlendirmeyi kaldırmanız gerekir.
The destructor is called after the header has been generated -- and calling exit from the destructor will not change the fact that that header has already been generated.
Oh, ve burada bir not olduğunu manual (quoting -- at the bottom of the page):
Note: Destructors called during the script shutdown have HTTP headers already sent.
Eğer "hehe
" dizesi görmüyorum nedeni budur: yıkıcı denir; Sadece ekranda görmüyorum ;-)
Ben örnekte bir dosya kullandı yüzden btw var ;-)