#42334 [NEW]: Error after ob_start causes buffer flush

From: Date: Sat, 18 Aug 2007 01:49:23 +0000
Subject: #42334 [NEW]: Error after ob_start causes buffer flush
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116288@lists.php.net to get a copy of this message
From:             ahaig at penguinmililtia dot net
Operating system: Mac OS X 10.4.10
PHP version:      5.2.3
PHP Bug Type:     Output Control
Bug description:  Error after ob_start causes buffer flush

Description:
------------
An error that occurs after ob_start() has been called causes the buffer to
flush. 

This makes it impossible to appropriately manage output for error handling
because sometimes text will randomly be inserted prior to the error output
(which means the error output has a full <html></html> tag set, but content
gets output before it - often open tags - which messes up tag pairing and
display).

I ran into this bug using Smarty templating. Smarty uses ob_get_contents()
to grab output from an include() of a compiled template that takes place
inbetween ob_start() and ob_end_clean(). Error handling for calls inside
the compiled template (which ends up being just combined php and html with
multiple <?php ?> pairs) end up with junk before their proper output. 

Reproduce code:
---------------
<?php

ob_start();
echo 'test';
trigger_error('error', E_USER_ERROR);
$output = ob_get_contents();
ob_end_clean();

?>

Expected result:
----------------
I expect to see output from trigger_error() (or any other error php might
throw) and nothing else. Non-error output should be buffered and not
displayed unless requested. Error output constitutes an exception to normal
processing, so should be output. 

The only other logical functioning I can see (although this would not, in
my mind, be the preferred functioning) is that the code should output
nothing at all, even the error output should go to the output buffer. This
would be absolutely consistent for the functions, but would make it
impossible to do any error handling inside a buffered section. 

Actual result:
--------------
Echo outputs 'test' and trigger_error outputs an error. 

-- 
Edit bug report at http://bugs.php.net/?id=42334&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42334&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42334&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42334&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42334&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=42334&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42334&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42334&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42334&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42334&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42334&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=42334&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=42334&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42334&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42334&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42334&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42334&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42334&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42334&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42334&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42334&r=mysqlcfg


Thread (10 messages)

« previous php.bugs (#116288) next »