Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: don't call disabled output buffer #16133

Open
kkmuffme opened this issue Sep 30, 2024 · 0 comments
Open

Bug: don't call disabled output buffer #16133

kkmuffme opened this issue Sep 30, 2024 · 0 comments

Comments

@kkmuffme
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants