I have a PHP class that creates a PNG image on the fly and sends it to browser. PHP manual says that I need to make sure that imagedestroy function is called at end to release the memory. Now, if I weren’t using a class, I would have some code like this:
function shutdown_func() { global $img; if ($img) imagedestroy($img); } register_shutdown_function('shutdown_func');
However, I believe that appropriate place for my class would be to place a call to imagedestroy in class’ destructor.
I failed to find out if destructors get called the same way shutdown functions does? For example, if execution stops when user presses the STOP button in browser.
Note: whatever you write in your answer, please point to some article or manual page (URL) that supports it.
I just tested with Apache, PHP being used as Apache module. I created an endless loop like this:
Here’s what I found out:
However, doing this:
shutdown_func gets called. So this means that class destuctor is not that good as shutdown functions.