diff --git a/UPGRADING b/UPGRADING index 7ccc9751c0d09..776f729c43a30 100644 --- a/UPGRADING +++ b/UPGRADING @@ -237,6 +237,10 @@ PHP 8.4 UPGRADE NOTES . New serial_hex parameter added to openssl_csr_sign to allow setting serial number in the hexadecimal format. +- Output Buffering Control: + . Output handler status flags passed to the flags parameter of ob_start + are now cleared. + - PDO: . getAttribute, enabled to get the value of ATTR_STRINGIFY_FETCHES. diff --git a/main/output.c b/main/output.c index 76d4e7709e846..2c2c13b672aaf 100644 --- a/main/output.c +++ b/main/output.c @@ -478,7 +478,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, default: user = ecalloc(1, sizeof(php_output_handler_user_func_t)); if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error)) { - handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER); + handler = php_output_handler_init(handler_name, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_USER); ZVAL_COPY(&user->zoh, output_handler); handler->func.user = user; } else { @@ -504,7 +504,7 @@ PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, php_output_handler *handler; zend_string *str = zend_string_init(name, name_len, 0); - handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL); + handler = php_output_handler_init(str, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_INTERNAL); handler->func.internal = output_handler; zend_string_release_ex(str, 0); diff --git a/main/php_output.h b/main/php_output.h index 852aab7fb9db0..d722eba953b47 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -43,6 +43,8 @@ #define PHP_OUTPUT_HANDLER_DISABLED 0x2000 #define PHP_OUTPUT_HANDLER_PROCESSED 0x4000 +#define PHP_OUTPUT_HANDLER_ABILITY_FLAGS(bitmask) ((bitmask) & ~0xf00f) + /* handler op return values */ typedef enum _php_output_handler_status_t { PHP_OUTPUT_HANDLER_FAILURE, diff --git a/tests/output/ob_start_flags.phpt b/tests/output/ob_start_flags.phpt new file mode 100644 index 0000000000000..a52ced6bd10a7 --- /dev/null +++ b/tests/output/ob_start_flags.phpt @@ -0,0 +1,31 @@ +--TEST-- +ob_start(): Ensure that user supplied handler type and status flags are erased +--FILE-- + $s, + 0, + PHP_OUTPUT_HANDLER_STDFLAGS | + PHP_OUTPUT_HANDLER_TYPE_INTERNAL | + PHP_OUTPUT_HANDLER_STARTED | + PHP_OUTPUT_HANDLER_DISABLED | + PHP_OUTPUT_HANDLER_PROCESSED +); + +$bitmask = ob_get_status()['flags']; + +var_dump($bitmask & PHP_OUTPUT_HANDLER_STDFLAGS); +var_dump($bitmask & PHP_OUTPUT_HANDLER_TYPE_USER); +var_dump($bitmask & PHP_OUTPUT_HANDLER_STARTED); +var_dump($bitmask & PHP_OUTPUT_HANDLER_DISABLED); +var_dump($bitmask & PHP_OUTPUT_HANDLER_PROCESSED); +?> +--EXPECT-- +int(112) +int(1) +int(0) +int(0) +int(0)