php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46897 ob_flush() should fail to flush unerasable buffers
Submitted: 2008-12-18 12:27 UTC Modified: 2012-01-17 12:46 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: robin_fernandes at uk dot ibm dot com Assigned: mike (profile)
Status: Closed Package: Output Control
PHP Version: 5.3CVS-2008-12-18 (snap) OS: *
Private report: No CVE-ID: None
 [2008-12-18 12:27 UTC] robin_fernandes at uk dot ibm dot com
Description:
------------
On 5_2 and 5_3, there is an inconsistency between ob_flush() and ob_get_flush() when attempting to flush a buffer created with the flag $erase=false:
 - ob_get_flush() raises a notice and does NOT flush the buffer; 
 - ob_flush() DOES flush the buffer.
 
Note that on HEAD, both ob_get_flush() and ob_flush() raise a notice and do NOT flush the buffer.
I think the behaviour in HEAD is correct. Here's a simple patch for 5_3 that resolves the inconsistency and makes it behave more like HEAD:

Index: output.c
===================================================================
RCS file: /repository/php-src/main/output.c,v
retrieving revision 1.167.2.3.2.4.2.9
diff -u -w -p -r1.167.2.3.2.4.2.9 output.c
--- output.c    18 Aug 2008 07:46:31 -0000      1.167.2.3.2.4.2.9
+++ output.c    18 Dec 2008 11:30:01 -0000
@@ -774,6 +774,10 @@ PHP_FUNCTION(ob_flush)
                php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush.");
                RETURN_FALSE;
        }
+       if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) {
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer %s", OG(active_ob_buffer).handler_name);
+               RETURN_FALSE;
+       }

        php_end_ob_buffer(1, 1 TSRMLS_CC);
        RETURN_TRUE;




More generally, the behaviour of output buffering functions when dealing with unerasable buffers could benefit from better docs. I will raise a separate doc bug with some suggestions.

Reproduce code:
---------------
<?php
function callback($string) {
	static $callback_invocations;
	$callback_invocations++;
	return "[callback:$callback_invocations]$string\n";
}

ob_start('callback', 0, false);

echo "Attempt to flush unerasable buffer - should fail... ";
var_dump(ob_flush());
// Check content of buffer after flush - if flush failed it should still contain the string above.
var_dump(ob_get_contents());
?>

Expected result:
----------------
[callback:1]Attempt to flush unerasable buffer - should fail...
Notice: ob_flush(): failed to flush buffer callback in %s on line 11
bool(false)
string(%d) "Attempt to flush unerasable buffer - should fail...
Notice: ob_flush(): failed to flush buffer callback in %s on line 11
bool(false)
"


Actual result:
--------------
[callback:1]Attempt to flush unerasable buffer - should fail... 
[callback:2]bool(true)
string(11) "bool(true)
"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 14:15 UTC] jani@php.net
In HEAD there is improved output buffering code. Hence the difference. And IMO, the proper fix for this is to simply backport the patch. (IIRC that's already done, just wasn't allowed to be committed to 5.3 for some stupid reason..)
 [2009-02-13 11:50 UTC] davidc@php.net
New NOTICE issued:

Notice: ob_flush(): failed to flush buffer callback. in %s on line %d
 [2012-01-17 12:46 UTC] mike@php.net
This bug has been fixed in SVN.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-01-17 12:46 UTC] mike@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: mike
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC