Are there situations in which this method would not be called?
I’m thinking to store a important variable into a persistent cache just before the cache object gets destroyed. This variable is used many times in the page so I wouldn’t like to update the cache with it every time the variable changes…
Let’s have a class:
And test code:
So basically: there are situations (fatal errors) when destructor won’t be called.
Ah and this question has the same answer as this one: When will __destruct not be called in PHP? (+/-)