[GIT-PULLS] [php-src] PR #23402: ext/standard: Change return type of header_register_callback() to true

[email protected] (lacatoire)
Newsgroups php.git-pulls
Message-ID <rn6zkmZOJgRiKz7A4CZSMPX0Ev6s79ZD88XHIaY34Zc@main.internal.php.net>
Pull Request: https://github.com/php/php-src/pull/23402
Author: lacatoire

`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:

```c
/* 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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.