php.net |  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
Votes:7
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
Description:
------------
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:
---------------
<?php

error_reporting(E_ALL);


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

    function __destruct()
    {
        $buffered_data = ob_get_contents();
        ob_end_clean();

        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: 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-28 09:51 UTC] sniper@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fix will be in PHP 5.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC