|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30578 Output buffers flushed before calling __desctruct() functions
Submitted: 2004-10-27 08:09 UTC Modified: 2005-04-29 02:32 UTC
Avg. Score:4.7 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:3 (50.0%)
From: anthony at ectrolinux dot com Assigned:
Status: Closed Package: Output Control
PHP Version: 5CVS-2005-03-07 OS: *
Private report: No CVE-ID: None
 [2004-10-27 08:09 UTC] anthony at ectrolinux dot com
During script termination, PHP's explicit output buffer flush should wait until all variables have gone -completely- out of scope. Using an instantiated object that manages buffers, the data has already been flushed before __destruct() is called, which prevents the script from properly finalizing data collection and flushing the output normally. This is not the appropriate behavior.

Reproduce code:


class Example
    function __construct()
        echo 'This should be displayed last.'."\n";

    function __destruct()
        $buffered_data = ob_get_contents();

        echo 'This should be displayed first.'."\n";
        echo 'Buffered data: '. $buffered_data;

$obj = new Example;


Expected result:
This should be displayed first.
Buffered data: This should be displayed last.

Actual result:
This should be displayed last.

Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in /--snip--/test.php on line 17
This should be displayed first.
Buffered data: 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-28 09:51 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fix will be in PHP 5.1

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 29 07:01:25 2023 UTC