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

 ID:                 46897
 Updated by:         m...@php.net
 Reported by:        robin_fernandes at uk dot ibm dot com
 Summary:            ob_flush() should fail to flush unerasable buffers
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Output Control
 Operating System:   *
 PHP Version:        5.3CVS-2008-12-18 (snap)
-Assigned To:        
+Assigned To:        mike
 Block user comment: N
 Private report:     N

 New Comment:

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.




Previous Comments:
------------------------------------------------------------------------
[2009-02-13 11:50:00] dav...@php.net

New NOTICE issued:

Notice: ob_flush(): failed to flush buffer callback. in %s on line %d

------------------------------------------------------------------------
[2008-12-18 14:15:20] j...@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..)

------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=46897&edit=1

Reply via email to