im trying to understand php constructor and destructor behaviour. Everything goes as expected with the constructor but i am having trouble getting the destructor to fire imp
The __destruct() magic function is executed when the object is deleted/destroyed (using unset). It is not called during shutdown of a script. When a PHP script finishes executing, it cleans up the memory, but it doesn't 'delete' objects as such, thus the __destruct() methods aren't called.
You may be thinking of the register_shutdown_function(), which is fired when your PHP script finishes executing.
function shutdown()
{
// code here
echo 'this will be called last';
}
register_shutdown_function('shutdown');