Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 973309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:15:36+00:00 2026-05-16T03:15:36+00:00

This is my first time posting to stackoverflow, but these threads have helped me

  • 0

This is my first time posting to stackoverflow, but these threads have helped me tremendously!

Anyhow, onto my question… Are there any instances when the destructor in PHP is NOT called? The reason I ask is because I have a mapper class which maps data to objects and in the constructor, I start a transaction and in the destructor I’ll call a commit (I’ll also have a member function which can also do the committal, if necessary). If there are any instances when the destructor isn’t called, I’d like to know so I can anticipate it happening and plan appropriately.

Thanks very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:15:36+00:00Added an answer on May 16, 2026 at 3:15 am
    • According to the manual, destructors are executed even if the script gets terminated using die() or exit():

      The destructor will be called even if script execution is stopped using exit(). Calling exit() in a destructor will prevent the remaining shutdown routines from executing.

    • According to this SO question, the destructor does not get executed when PHP’s execution time limit is reached (Confirmed on Apache 2, PHP 5.2 on Windows 7).

    • The destructor also does not get executed when the script terminates because the memory limit was reached. (Just tested)

    • The destructor does get executed on fatal errors (Just tested) Update: The OP can’t confirm this – there seem to be fatal errors where things are different

    • It does not get executed on parse errors (because the whole script won’t be interpreted)

    • The destructor will certainly not be executed if the server process crashes or some other exception out of PHP’s control occurs.

    All in all, it looks pretty reliable.

    The downside of doing things other than cleanup in the destructor, though, is that your options there are somewhat limited. You can’t throw exceptions any more (except if you catch them again inside the destructor), you can’t output any error messages, you can’t really rely on the presence of other objects (like the database interface) any more ….. I don’t have deep experience in working with destructors but I’m not sure whether what you’re planning to do is a feasible idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer remove float:left from dl.icons dd May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer Timer tasks are executed on the Event Dispatching thread so… May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer <iframe name="myIframe" width="800" height="600" src="page.htm"> </iframe> and then if you… May 16, 2026 at 10:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is my first time posting on Stackoverflow, but I've been reading through many
This is the first time I am posting a question on stackoverflow, so please
(I am sorry, I wanted to ask this question on meta first, but it
Good morning, all. This is my first question on stackoverflow, so hopefully this isn't
This little search example works but only the first time. How do I clear
I will start by saying this is the first time I have done anything
this is my first time using Eclipse, and my first time programming in a
This is my first time using the synchronized keyword, so I am still unsure
First, thanks for all the help I've received so far from StackOverflow. I've learned
First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.