Is a class destructor in PHP predictable? When is the destructor called?
Like in many languages, will a class destructor be called as soon as the object goes out of scope?
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.
http://php.net/manual/en/language.oop5.decon.php
It's called when the first of these conditions are met:
In short, you should not rely on it always being called, because the script may not finish cleanly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With