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 9124623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:36:51+00:00 2026-06-17T06:36:51+00:00

i have the following logic in my model: if ( $switch_obj->connect() ) { if

  • 0

i have the following logic in my model:

if ( $switch_obj->connect() )  {
  if ( $data = $switch_obj->showIntAll() )  {
        $switch_obj->disconnect();  
        return $data;
  }
  else  {
     $switch_obj->disconnect();
     throw new Exception('Empty Data Set');
  }
}
else  {                                     
   throw new Exception('Connection');                                  
    }

This switch_obj that’s being called has logic in it’s constructor and destructor to increment / decrement counters respectively. (saved in a class called testclass).
So each time an object of type testclass is instantiated, a counter is increased. And then when destroyed, it’s decremented.
However, I’ve just discovered a scenario that I’m not handling.

Fatal error: Call to undefined method testclass::showIntAll() in
/var/www/myapp/application/models/test_model.php on line 215

It’s clear that I’m calling a method that doesn’t exist, which I will resolve. But my question is this: in creating this error, i can see that the counter has already been incremented … but not decremented because once this error is thrown, it never returns to the destructor method in my class.
How would I program for these types of scenarios? Obviously, in production, I won’t get getting errors because of missing methods in testclass… but in case I do get an unexpected error where the testclass constructor is called and then it bombs, I’m just wondering what the best way is to handle this.

  • 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-06-17T06:36:51+00:00Added an answer on June 17, 2026 at 6:36 am

    You might achieve something with register_shutdown_function. Your constructor could register a clean-up function which would get called if an error would occur. You’d have to be careful not to call the clean-up code twice though (once from the destructor and once from this registered function.

    Not a pretty solution, but it could work 🙂

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

Sidebar

Related Questions

I currently have the following in one solution: Core Project (data access, biz logic,
I have a Backbone Model with validation logic. I have bound the following method
I need syntax help with the following code logic: I have a code block
I have the following: class AccountAdmin(models.Model): account = models.ForeignKey(Account) is_master = models.BooleanField() name =
Let just say I have the following data models: public class Account { public
I have the following situation: A project MyCompany.MyProject.Domain which contains my domain model, and
I have the following.. <span class=error>@Model.ErrorMessage</span> The problem is that the css for error
I have the following design: (source: kawoolutions.com ) Simple logic: Foos uses a multi-column
I have the following form declaration for a new kindergarten <%= form_for @kindergarten, :html
I have the following form declaration for a new kindergarten <%= form_for @kindergarten, :html

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.