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

From: Date: Mon, 28 Feb 2022 04:01:37 +0000
Subject: Bug #42334 [PATCH]: Error after ob_start causes buffer flush
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240071@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 Patch added by: freeballin572@gmail.com 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: Irrelevant PHP Version: irrelevant Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: Fix some grammatical errors on home page On GitHub: https://github.com/php/web-doc/pull/18 Patch: https://github.com/php/web-doc/pull/18.patch Previous Comments: ------------------------------------------------------------------------ [2022-02-28 04:00:12] freeballin572 at gmail dot com The following pull request has been associated: Patch Name: usability: link to user profiles also on icon and full name On GitHub: https://github.com/php/web-people/pull/14 Patch: https://github.com/php/web-people/pull/14.patch ------------------------------------------------------------------------ [2022-02-28 03:58:00] freeballin572 at gmail dot com The following pull request has been associated: Patch Name: Enhancement: Expose happy path On GitHub: https://github.com/php/web-php/pull/406 Patch: https://github.com/php/web-php/pull/406.patch ------------------------------------------------------------------------ [2016-09-24 05:05:50] yohgaki@php.net Instead of requesting changes in output buffer, request use of exception or make E_ERROR catchable. ------------------------------------------------------------------------ [2016-09-24 01:15:56] mbutscher at gmx dot de One possible way to create a fatal error (ok, only if programmer is lazy) function foo() ... if (<usually false>) foop(); // spelling error As long as the if-clause is false the error won't be noticed. ------------------------------------------------------------------------ [2016-09-24 00:43:06] yohgaki@php.net Output buffer is flushed when PHP terminates execution. Current PHP cannot catch E_ERROR. This prevents cleaning up buffer, but not E_USER_ERROR. e.g. set_error_handler(function ($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting return; } switch ($errno) { case E_USER_ERROR: ob_clean(); //////////////// CLEAN UP BUFFER ////////////////////// echo "<b>My ERROR</b> [$errno] $errstr<br />\n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; exit(1); break; case E_USER_WARNING: echo "<b>My WARNING</b> [$errno] $errstr<br />\n"; break; case E_USER_NOTICE: echo "<b>My NOTICE</b> [$errno] $errstr<br />\n"; break; default: echo "Unknown error type: [$errno] $errstr<br />\n"; break; } /* Don't execute PHP internal error handler */ return true; }); ob_start(); echo 'test'; trigger_error('error', E_USER_ERROR); $output = ob_get_contents(); ob_end_clean(); ?> We have not many problematic E_ERRORs in our code base now. Most problematic E_ERRORs are in SOAP module. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=42334 -- Edit this bug report at https://bugs.php.net/bug.php?id=42334&edit=1

« previous php.bugs (#240071) next »