Skip to content

ext/standard: Change return type of header_register_callback() to true - #23402

Merged
LamentXU123 merged 1 commit into
php:masterfrom
lacatoire:fix/header-register-callback-true-return
Aug 21, 2026
Merged

ext/standard: Change return type of header_register_callback() to true#23402
LamentXU123 merged 1 commit into
php:masterfrom
lacatoire:fix/header-register-callback-true-return

Conversation

@lacatoire

Copy link
Copy Markdown
Member

header_register_callback() is declared as returning bool, but PHP_FUNCTION(header_register_callback) in main/SAPI.c has a single non-throwing exit, RETURN_TRUE.

The false return is a leftover from PHP 7:

/* php-7.0.0, main/SAPI.c */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback_func) == FAILURE) {
    return;
}
if (!zend_is_callable(callback_func, 0, NULL)) {
    RETURN_FALSE;
}

PHP 8.0.0 moved the check to the f parameter specifier, which throws a TypeError, and the RETURN_FALSE went away with it. The declared type was never adjusted.

Checked on 8.4.22 and 8.5.8: every accepted callable form (closure, function name, Class::method, [$obj, 'method'], __invoke object, first-class callable syntax) returns true, an invalid callback throws TypeError, and registering after headers_sent() is already true — the case where the callback is knowingly discarded — returns true as well.

true being a subtype of bool, the only observable change is what Reflection reports.

Whether the headers_sent branch ought to report failure instead is a behaviour question, deliberately left out of this change.

…back()

The function has a single non-throwing exit, RETURN_TRUE (main/SAPI.c).
The false return disappeared in PHP 8.0.0: until then an invalid callback
was rejected with RETURN_FALSE, whereas the zend_parse_parameters() 'f'
specifier introduced there throws a TypeError. Registering a callback
after the headers have been sent, the one case where the callback is
knowingly discarded, also returns true.

ksort(), asort() and natsort() already declare true in the same stub.

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems correct. But since this is sapi stuff cc @NattyNarwhal

@NattyNarwhal NattyNarwhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change is trivial.

@LamentXU123
LamentXU123 merged commit f89291a into php:master Aug 21, 2026
17 of 18 checks passed
@LamentXU123

Copy link
Copy Markdown
Member

Thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants