Bug #78495 [Opn->Csd]: Allow any functions in ob_start user's callback
| From: | girgias@php.net | Date: | Thu, 25 Jan 2024 13:37:31 +0000 |
| Subject: | Bug #78495 [Opn->Csd]: Allow any functions in ob_start user's callback | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-246338@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78495&edit=1
ID: 78495
Updated by: girgias@php.net
Reported by: michael dot vorisek at email dot cz
Summary: Allow any functions in ob_start user's callback
-Status: Open
+Status: Closed
Type: Bug
Package: Output Control
Operating System: Any
PHP Version: 7.3.9
-Assigned To:
+Assigned To: girgias
Block user comment: N
Private report: N
New Comment:
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
Previous Comments:
------------------------------------------------------------------------
[2024-01-07 11:43:33] haszika80 at gmail dot com
This has been fixed and produces OP's expected result.
------------------------------------------------------------------------
[2019-12-17 18:26:45] archon810 at gmail dot com
Possibly related: https://bugs.php.net/bug.php?id=78565.
------------------------------------------------------------------------
[2019-09-05 12:34:35] michael dot vorisek at email dot cz
Description:
------------
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:
---------------
<?php
// capture any unexpected output and exit execution
ob_start(function($buffer) {
ob_end_clean();
echo 'unexpected output: ' . $buffer . "\n";
exit;
}, 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78495&edit=1