ID:               46897
 Updated by:       j...@php.net
 Reported By:      robin_fernandes at uk dot ibm dot com
 Status:           Open
 Bug Type:         Output Control
 Operating System: *
 PHP Version:      5.3CVS-2008-12-18 (snap)
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[2008-12-18 12:27:16] 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)
"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46897&edit=1

Reply via email to