From: robin_fernandes at uk dot ibm dot com
Operating system: *
PHP version: 5.3CVS-2008-12-18 (snap)
PHP Bug Type: Output Control
Bug description: ob_flush() should fail to flush unerasable buffers
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 bug report at http://bugs.php.net/?id=46897&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46897&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46897&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46897&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=46897&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=46897&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=46897&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=46897&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=46897&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=46897&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=46897&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=46897&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46897&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46897&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=46897&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46897&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46897&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=46897&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=46897&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=46897&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=46897&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=46897&r=mysqlcfg