php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #32406 PHP claims that headers are set when __destruct is called
Submitted: 2005-03-22 00:16 UTC Modified: 2005-03-23 11:34 UTC
From: webmaster at benliles dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.* 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: webmaster at benliles dot com
New email:
PHP Version: OS:

 

 [2005-03-22 00:16 UTC] webmaster at benliles dot com
Description:
------------
It appears that PHP has a flag set for headers already being sent when __destruct() is called despite the fact that nothing is being sent before that.  This has been seen in PHP 5.0.2 and PHP 5.0.3 with two different operating systems.  This is not documented as claimed in an earlier bug report.

Reproduce code:
---------------
<?
class letsTestThis {

 public function __destruct() {
  if (!headers_sent($file,$line)) {
   header("Content-type: text/xml");
   echo "Some cool XML!";
  } else {
   echo "Headers already sent in file: ".$file."<BR>\nOn Line: ".$line."<BR>\n";
  }
 }
}

$test = new letsTestThis();
?>

Expected result:
----------------
Some cool XML



Actual result:
--------------
Headers already sent in file: 
On Line: 0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-22 00:19 UTC] helly@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

__destruct is called during script shut down - that is everything has already been sent. Add a '$test = NULL;' in front of the '?>' and you'll see.
 [2005-03-22 01:04 UTC] webmaster at benliles dot com
We are output buffering and in the destructor for a page class, we dump the output buffer.  There is nothing in the documentation to indicate when headers would be sent before this point.

Also, the headers_sent function is not reporting correct information.  The file name is blank and line number is zero.
 [2005-03-22 09:13 UTC] derick@php.net
Marcus is right, this is expected and should be documented if it's not already
 [2005-03-23 11:34 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Destructor is called during the script shutdown so headers are always already sent."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 10:01:29 2025 UTC