Bug #42334 [Com]: Error after ob_start causes buffer flush

From: Date: Fri, 23 Sep 2016 23:36:50 +0000
Subject: Bug #42334 [Com]: Error after ob_start causes buffer flush
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204224@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42334&edit=1

 ID:                 42334
 Comment by:         mbutscher at gmx dot de
 Reported by:        ahaig at penguinmililtia dot net
 Summary:            Error after ob_start causes buffer flush
 Status:             Not a bug
 Type:               Bug
 Package:            Output Control
 Operating System:   Mac OS X 10.4.10
 PHP Version:        5.2.3
 Block user comment: N
 Private report:     N

 New Comment:

At least if ob_start is called like e.g.

ob_start(NULL, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE);

it should (as far as I understand) forbid to flush the buffer contents even on error.


Previous Comments:
------------------------------------------------------------------------
[2007-08-20 07:50:58] jani@php.net

Hint: Try changing the error to E_USER_WARNING instead.
(fatal errors stop script processing and are..eh..FATAL..:)

------------------------------------------------------------------------
[2007-08-19 20:00:46] jani@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php



------------------------------------------------------------------------
[2007-08-18 01:49:23] ahaig at penguinmililtia dot net

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 this bug report at https://bugs.php.net/bug.php?id=42334&edit=1


Thread (10 messages)

« previous php.bugs (#204224) next »