[wp-trac] [WordPress Trac] #64108: Triggered errors are not displayed when applying template enhancement output buffer filters

WordPress Trac noreply at wordpress.org
Thu Oct 16 19:26:37 UTC 2025


#64108: Triggered errors are not displayed when applying template enhancement
output buffer filters
--------------------------+--------------------------
 Reporter:  westonruter   |       Owner:  westonruter
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  6.9
Component:  General       |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+--------------------------
Description changed by westonruter:

Old description:

> This is follow up to #43258.
>
> Attempting to `echo` during a user output buffer callback does not add
> anything to the output, and this is now deprecated in PHP 8.5 as
> [https://core.trac.wordpress.org/ticket/43258#comment:73 discovered] by
> @swissspidy (see initial fix in [60945]), and was
> [https://core.trac.wordpress.org/ticket/43258#comment:74 noted] by
> @jorbin:
>
> > More info on the deprecation: https://github.com/php/php-
> src/commit/07f1cfd9b01ff0f3720c1a5580b9e263eec5fce1 and
> https://wiki.php.net/rfc/deprecations_php_8_4#:~:text=has%20been%20closed.-,Deprecate%20producing%20output%20in%20a%20user%20output%20handler,buffering%20function%20in%20an%20output%20handler%20will%20emit%20a%20Fatal%20Error.,-Deprecate%20producing%20output
>
> Of note:
>
> > '''Deprecate producing output in a user output handler'''
> >
> > Because an output handler should just be manipulating the incoming
> buffer, any output that it produces is discarded. As such, issues within
> an output handler can go unnoticed and be hard to debug.
> >
> > Therefore, we propose deprecating producing any output in an output
> handler, in the same way as attempting to use an output buffering
> function in an output handler will emit a Fatal Error.
>
> Currently when `WP_DEBUG_DISPLAY` is enabled (and thus `display_errors`
> is on), calls to `_doing_it_wrong()` and `wp_trigger_error()` in
> callbacks for the `wp_template_enhancement_output_buffer` filter are
> problematic. In reality, this has been a problem already for plugins that
> open their own output buffers and either trigger errors in their output
> buffer callback or provide extensibility for other plugins which can
> cause errors.
>
> We should better handle errors triggered during a user output handler. We
> capture with an error handler and then when `display_errors` is on we can
> append the errors as HTML to the response.

New description:

 This is follow up to #43258.

 Attempting to `echo` during a user output buffer callback does not add
 anything to the output, and this is now deprecated in PHP 8.5 as
 [https://core.trac.wordpress.org/ticket/43258#comment:73 discovered] by
 @swissspidy (see initial fix in [60945]), and was
 [https://core.trac.wordpress.org/ticket/43258#comment:74 noted] by
 @jorbin:

 > More info on the deprecation: https://github.com/php/php-
 src/commit/07f1cfd9b01ff0f3720c1a5580b9e263eec5fce1 and
 https://wiki.php.net/rfc/deprecations_php_8_4#:~:text=has%20been%20closed.-,Deprecate%20producing%20output%20in%20a%20user%20output%20handler,buffering%20function%20in%20an%20output%20handler%20will%20emit%20a%20Fatal%20Error.,-Deprecate%20producing%20output

 Of note:

 > '''Deprecate producing output in a user output handler'''
 >
 > Because an output handler should just be manipulating the incoming
 buffer, any output that it produces is discarded. As such, issues within
 an output handler can go unnoticed and be hard to debug.
 >
 > Therefore, we propose deprecating producing any output in an output
 handler, in the same way as attempting to use an output buffering function
 in an output handler will emit a Fatal Error.

 Currently when `WP_DEBUG_DISPLAY` is enabled (and thus `display_errors` is
 on), calls to `_doing_it_wrong()` and `wp_trigger_error()` in callbacks
 for the `wp_template_enhancement_output_buffer` filter are problematic. In
 reality, this has been a problem already for plugins that open their own
 output buffers and either trigger errors in their output buffer callback
 or provide extensibility for other plugins which can cause errors.

 We should better handle errors triggered during a user output handler. We
 capture with an error handler and then when `display_errors` is on we can
 append the errors as HTML to the response.

 Example plugin which emits errors before and during the output buffer
 callback:

 {{{#!php
 <?php
 /**
  * Plugin Name: Emit Errors Before and During Output Buffer Callback
  * Requires at least: 6.9-alpha
  */

 namespace EmitErrorsBeforeAndDuringOutputBufferCallback;

 function emit_notices() {
         _doing_it_wrong( __FUNCTION__, '✅ You are doing it wrong at ' .
 current_action(), '0.0.0' );
         wp_trigger_error( __FUNCTION__, '✅ Notice ' . current_action(),
 E_USER_NOTICE );
         wp_trigger_error( __FUNCTION__, '✅ Deprecated ' .
 current_action(), E_USER_DEPRECATED );
         wp_trigger_error( __FUNCTION__, '✅ Warning ' . current_action(),
 E_USER_WARNING );
 }

 add_action( 'wp_before_include_template', __NAMESPACE__ . '\emit_notices'
 );

 add_filter(
         'wp_template_enhancement_output_buffer',
         static function ( $buffer ) {
                 emit_notices();
                 return $buffer;
         }
 );

 }}}

 With PHP 8.5 active, this results in the following errors being printed
 before the HTML document is served:

 * Deprecated: ob_end_flush(): Producing output from user output handler
 wp_finalize_template_enhancement_output_buffer is deprecated in
 /var/www/src/wp-includes/functions.php on line 5481
 * Notice: Function
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices was called
 incorrectly. ✅ You are doing it wrong at wp_before_include_template
 Please see Debugging in WordPress for more information. (This message was
 added in version 0.0.0.) in /var/www/src/wp-includes/functions.php on line
 6131
 * Notice: EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅
 Notice wp_before_include_template in /var/www/src/wp-
 includes/functions.php on line 6131
 * Deprecated:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅
 Deprecated wp_before_include_template in /var/www/src/wp-
 includes/functions.php on line 6131
 * Warning: EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices():
 ✅ Warning wp_before_include_template in /var/www/src/wp-
 includes/functions.php on line 6131

 Notice only the four errors printed during the
 `wp_before_include_template` action are printed. None of the errors during
 the `wp_template_enhancement_output_buffer` filter are printed. They all
 appear in the error log, however:

 {{{
 [16-Oct-2025 19:23:00 UTC] PHP Notice:  Function
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices was called
 <strong>incorrectly</strong>. ✅ You are doing it wrong at
 wp_before_include_template Please see <a
 href="https://developer.wordpress.org/advanced-administration/debug/debug-
 wordpress/">Debugging in WordPress</a> for more information. (This message
 was added in version 0.0.0.) in /var/www/src/wp-includes/functions.php on
 line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Notice:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅ Notice
 wp_before_include_template in /var/www/src/wp-includes/functions.php on
 line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Deprecated:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅
 Deprecated wp_before_include_template in /var/www/src/wp-
 includes/functions.php on line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Warning:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅ Warning
 wp_before_include_template in /var/www/src/wp-includes/functions.php on
 line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Notice:  Function
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices was called
 <strong>incorrectly</strong>. ✅ You are doing it wrong at
 wp_template_enhancement_output_buffer Please see <a
 href="https://developer.wordpress.org/advanced-administration/debug/debug-
 wordpress/">Debugging in WordPress</a> for more information. (This message
 was added in version 0.0.0.) in /var/www/src/wp-includes/functions.php on
 line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Notice:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅ Notice
 wp_template_enhancement_output_buffer in /var/www/src/wp-
 includes/functions.php on line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Deprecated:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅
 Deprecated wp_template_enhancement_output_buffer in /var/www/src/wp-
 includes/functions.php on line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Warning:
 EmitErrorsBeforeAndDuringOutputBufferCallback\emit_notices(): ✅ Warning
 wp_template_enhancement_output_buffer in /var/www/src/wp-
 includes/functions.php on line 6131
 [16-Oct-2025 19:23:00 UTC] PHP Deprecated:  ob_end_flush(): Producing
 output from user output handler
 wp_finalize_template_enhancement_output_buffer is deprecated in
 /var/www/src/wp-includes/functions.php on line 5481
 [16-Oct-2025 19:23:00 UTC] PHP Deprecated:  ob_end_flush(): Producing
 output from user output handler {closure:od_buffer_output():54} is
 deprecated in /var/www/src/wp-includes/functions.php on line 548
 }}}

 In PHP 8.4, the deprecation notice for `ob_end_flush()` does not appear,
 and neither to any of the errors emitted during the output buffer
 callback.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64108#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list