header

FunctionParams and return types changed in PHP 8.0

Send a raw HTTP header.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

header Function synopsis

header(
    string $header,
    bool $replace = true,
    int $response_code = 0
  ): void

Parameters

$header

Typestring

The header string.

$replace

OptionalTypeboolDefault valuetrue

The optional $replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in false as the second argument you can force multiple headers of the same type. For example:

$response_code

OptionalTypeintDefault value0

Forces the HTTP response code to the specified value. Note that this parameter only has an effect if the $header is not empty.

Return value

The header function is a void function; it does not return any values.

Changes to the header Function

PHP 8.0

  • Return type added: void
  • Parameter type added for parameter #1 ($header): string
  • Parameter type added for parameter #2 ($replace): bool
  • Parameter default value added for position #2 ($replace): true
  • Parameter name of parameter #3 changed: $http_response_code to $response_code
  • Parameter type added for parameter #3 ($response_code): int
  • Parameter default value added for position #3 ($response_code): 0
  header(
-     $header,
+     string $header,
-     $replace,
+     bool $replace = true,
-     $http_response_code
+     int $response_code = 0
-   )
+   ): void

header Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes