php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46152 Exit() don't stop execute
Submitted: 2008-09-22 12:55 UTC Modified: 2008-09-22 21:30 UTC
From: paszczak at thecamels dot org Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: paszczak at thecamels dot org
New email:
PHP Version: OS:

 

 [2008-09-22 12:55 UTC] paszczak at thecamels dot org
Description:
------------
Why exit don't stop execute of PHP script?

Reproduce code:
---------------
class innaklasa
{
    public function __construct()
    {    
        print "inna klasa<br />";
    }
    public function zrob()
    {    
        print "inna klasa zrob<br />";
    }
}
class klasa
{
    public function __construct()
    {        
        print "konstruktor<br />";
    }
    public function __destruct()
    {
        print "destruktor<br />";
        $innaklasa = new innaklasa;
        $innaklasa->zrob();
    }
}
$c = new klasa;
exit;

Expected result:
----------------
konstruktor

Actual result:
--------------
konstruktor
inna klasa
inna klasa zrob

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-22 14:13 UTC] tularis@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Destructors are called after request finishes and are meant to handle any cleanup required (ie. closing database connections). This is intended behaviour.
 [2008-09-22 21:30 UTC] paszczak at thecamels dot org
Maybe its not a bug. But if I want to terminate the current script (immediately), which function should I use?

http://pl2.php.net/manual/pl/function.exit.php
exit &#8212; Output a message and terminate the current script

I thought that die() are called destructors after request finishes and are meant to handle, but exit() terminate the current script immediately.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 11:01:34 2025 UTC