header_register_callback()
header_register_callback() — Call a header function.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.4.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Registers a function that will be called when PHP starts sending output.
Signature
header_register_callback(callable $callback): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $callback | callable | Function called just before the headers are sent. It gets no parameters and the return value is ignored. |
Return value
Returns true on success or false on failure.
Example
A runnable snippet:
header('Content-Type: text/plain'); header('X-Test: foo'); function foo() { foreach (headers_list() as $header) { if (strpos($header, 'X-Powered-By:') !== false) { header_remove('X-Powered-By'); } header_remove('X-Test'); } } $result = header_register_callback('foo'); echo "a";
Output:
Content-Type: text/plain a
See also
headers_list(), header_remove(), header()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page header_register_callback() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.