php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28489 Destructor sending headers?
Submitted: 2004-05-22 16:24 UTC Modified: 2004-05-22 17:39 UTC
From: bonebreaker at free dot fr Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0RC2 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bonebreaker at free dot fr
New email:
PHP Version: OS:

 

 [2004-05-22 16:24 UTC] bonebreaker at free dot fr
Description:
------------
__destruct() appears to be automatically sending headers before it's ran.

Output buffering can't prevent this behaviour.

Tested on Windows XP, Apache 2.0.48

Reproduce code:
---------------
class Test {
    function __construct()
    {
        $this->_string = '__construct()<br />';
    }

    function __destruct()
    {
        if (headers_sent($file, $line)) {
            $this->_string .= 'Headers sent in ' . $file . ' on line ' . $line;
        } else {
            $this->_string .= '__destruct()';
        }
        print $this->_string;
    }
}

$test = new Test();

Expected result:
----------------
__construct()
__destruct()

Actual result:
--------------
__construct()
Headers sent in on line 0


Though headers_sent() returns true, $file and $line still have default values.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-22 17:39 UTC] derick@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

Headers are sent before dtors are run, that\'s expected (and normal) behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC