|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78495 Allow any functions in ob_start user's callback
Submitted: 2019-09-05 12:34 UTC Modified: -
From: michael dot vorisek at email dot cz Assigned:
Status: Open Package: Output Control
PHP Version: 7.3.9 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:


 [2019-09-05 12:34 UTC] michael dot vorisek at email dot cz
Currently the ob_start user's callback is executed in some special context and (at least) these functions behave not as expected:
- ob_end_clean
- exit

The "ob_end_clean" is not supported as "Cannot use output buffering in output buffering display handlers".

But the "exit" should be fully supported as there is no other way to interrupt the code execution and get shutdown handlers executed. Obviously the shutdown handlers should be able to output some data or manipulate with the output buffering.

The desired execution flow be the following:
standard code...
-- ob handler called
---- stop ob handler execution if an exception is thrown or exit is called
-- exit the ob handler context and
   - if an exception was thrown handle the exception as uncaught in global context and
   - exit the main execution, i.e. start processing shutdown handlers as if normal exit was called (if no exit was called yet)

Test script:

// capture any unexpected output and exit execution
ob_start(function($buffer) {
    echo 'unexpected output: ' . $buffer . "\n";
}, 1);

// do some work on shutdown
register_shutdown_function(function() {
    echo 'shutting down';

echo 'test_1';
echo 'test_2';

Expected result:
Fatal error: ob_end_clean(): Cannot use output buffering in output buffering display handlers in C:\Users\mvorisek\Desktop\x.php on line 5
shutting down

Actual result:
unexpected output: test_1
shutting down


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-17 18:26 UTC] archon810 at gmail dot com
Possibly related:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 21:01:29 2023 UTC