Skip to content

Bug: don't call disabled output buffer #16133

@kkmuffme

Description

@kkmuffme

Description

When you check if PHP_OUTPUT_HANDLER_DISABLED is set with var_dump( ob_get_status( true ) ); you see it's set. The ob callback is still called every time, however with an empty string.
If the output buffer is disabled, the callback shouldn't be called at all.

https://3v4l.org/AbBH1

The following code:

<?php

function my_cb( $a ) {
	return 'AAA' . PHP_EOL . $a . 'BBB' . PHP_EOL;
}

function my_cb2( $a ) {
	if ( $a === 'XXX' ) {
		return false;	
	}
	if ( $a === '' ) {
	    $a = 'EMPTY';
	}
	
	return 'CCC' . PHP_EOL . $a . 'DDD' . PHP_EOL;
}

ob_start( 'my_cb', 0 );

ob_start( 'my_cb2', 0 );

echo "XXX";

ob_flush();

#var_dump( ob_get_status( true ) );

echo "ONE" . PHP_EOL;

ob_flush();

echo "TWO" . PHP_EOL;

ob_flush();

Resulted in this output:

AAA
XXXONE
CCC
EMPTYDDD
TWO
CCC
EMPTYDDD
BBB

But I expected this output instead:

AAA
XXXONE
TWO
BBB

PHP Version

PHP 8.3.x

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions