0

I am using php 7.1, Zend Framework 3. I am using the destructor on a class to remove a lock which I create in the constructor. In this case setting I update via API.
It appears that whenever my script times out, as in set_time_limit() is exceeded, or if the script throws an exception, my destructor is not being called. Is this expected behavior of php? Should I be catching and handling the error?

  • 1
    The destructor should always be called; but code that depends on object state may not run correctly, as state is not guaranteed to be defined at that point – Mark Baker Nov 01 '17 at 17:03
  • Have you checked that the destructor is called under normal conditions? i.e. by logging from the destructor? Does the logging not happen when the script throws an exception? It may be worth intercepting the 'shutdown processes' and checking what is happening with your object? see: https://stackoverflow.com/questions/4410632/handle-fatal-errors-in-php-using-register-shutdown-function#4410769 – Ryan Vincent Nov 01 '17 at 18:46
  • Yes, the destructor is called under normal conditions. I think my issue has more to depend on object state. I'm looking for a result to be filled in to an API, but there may not be values initialized. – Andrew Stokinger Nov 02 '17 at 17:49
  • The destructor is not called if there is a fatal error. Fatal errors include *uncaught* exceptions and timeouts. – NikiC Nov 03 '17 at 13:00

0 Answers0