php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55428 E_RECOVERABLE_ERROR when output buffering in output buffering handler
Submitted: 2011-08-15 22:00 UTC Modified: 2014-12-27 19:57 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nicolas dot grekas+php at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Output Control
PHP Version: 5.3.6 OS: any
Private report: No CVE-ID: None
 [2011-08-15 22:00 UTC] nicolas dot grekas+php at gmail dot com
Description:
------------
Output buffering inside output buffering handler is currently forbidden.

Ideally, this limitation could be removed, but as this may be too much work, I mostly really miss some way to test whether my code is running inside an output buffering handler or not (for example in a custom error handler).

PHP really miss a way to check for this situation.

Currently, when using output buffering in an output buffering handler context, an E_ERROR is thrown. Could it be possible to trigger an E_RECOVERABLE_ERROR instead? This would allow me to catch the situation and degrade gracefully.

Or maybe a new special function "ob_in_handler()", returning a boolean, is a better idea ?

Test script:
---------------
<?php

ob_start('abc');

function abc()
{
    ob_start();
}

?>

Expected result:
----------------
PHP Catchable fatal error:  ob_start(): Cannot use output buffering in output buffering display handlers in [...] on line 5

Actual result:
--------------
PHP Fatal error:  ob_start(): Cannot use output buffering in output buffering display handlers in [...] on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-22 14:22 UTC] kalle@php.net
I agree that we should change to use E_RECOVERABLE_ERROR here, as we don't leave the Engine in an unresolverable state (as the output layer is in the PHP part of the package).

As for the function suggestion, it doesn't make much sense to add a function to check if you are in a function for a function which purpose is to be used as a callback for ob_start().
 [2011-08-22 14:24 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: kalle
 [2014-12-27 19:57 UTC] kalle@php.net
-Status: Assigned +Status: Closed
 [2014-12-27 19:57 UTC] kalle@php.net
The fix for this bug has been committed.

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.

This change is now implemented in PHP7.
 [2014-12-27 20:00 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=335401
Log: Changelog for FR #55428
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC