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

  • SEARCH
  • Home
  • 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 8184455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:30:35+00:00 2026-06-07T01:30:35+00:00

Working with an MVC framework and the controller renders the page in the destructor.

  • 0

Working with an MVC framework and the controller renders the page in the destructor. I am downloading a file through php, so at the end of the action the script should end.

How to end the script without calling the destructor?

Is there a better solution?

exit and die call the destructor.

  • 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-07T01:30:36+00:00Added an answer on June 7, 2026 at 1:30 am

    As David said: you’ll need to call exit() inside a destructor to stop it.

    If however you just want to halt the visual output caused by these destructors but not any other side-effects (file closing, database connection closing) they might do, then it’s best to just kill the further output but leave the destructors alone. Which in my opinion would be the route to take since destructors tend to be there for one important reason: cleaning up.

    you can do that by manipulating buffered output:

    <?php
    class Tester{
       public function devNull($string){
           return "";
       }
    
       public function runAndBreak(){
            print "run" . PHP_EOL;
    
            // if any output buffer is working, flush it and close it
            if(ob_get_level()) ob_end_flush();
    
            // redirect new buffer to our devNull
            ob_start(array($this,'devNull'));
            exit();
            print "still running";
    
       }
    
       function __destruct(){
            print "destructor" . PHP_EOL;
       }
    
    }
    
    $t = new Tester();
    $t->runAndBreak();
    

    this will only print run and not what’s in the destructor. It’s done by giving your own callback routine to ob_start that handles and then returns the output. In our case here we simply discard it by returning an empty string.

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

Sidebar

Related Questions

I am working with a custom MVC PHP framework and the index page (acting
I'm working on a small MVC framework in PHP for an exercise. PHP, however,
I am working with master page in ASP.NET (3.5) MVC Framework (1.0). I am
I am working through Steve Sanderson's book Pro ASP.NET MVC Framework and I having
I'm working through the ASP.NET MVC article at http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx . (Note: Some of the
I am working on an MVC framework in PHP but I work with java
When working with an MVC framework and querying the database from the controller using
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I'm working with a PHP MVC Framework. Works really well. I like the separation
I am working with an MVC framework (specifically, PHP's CodeIgniter ). I am trying

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.