get_headers
Function • Params and return types changed in PHP 8.0
Fetches all the headers sent by the server in response to an HTTP request.
get_headers Function synopsis
get_headers(
string $url,
bool $associative = false,
$context = null
): array|false
Parameters
$url
Typestring
The target URL.
$associative
OptionalTypeboolDefault valuefalse
If the optional $associative parameter is set to true,
get_headers parses the response and sets the
array's keys.
$context
OptionalDefault valuenull
A valid context resource created with
stream_context_create, or null to use the
default context.
Return value
Typearray|false
Returns an indexed or associative array with the headers, or false on
failure.
Changes to the get_headers Function
PHP 8.0
- Return type added:
array|false - Parameter type added for parameter #1 (
$url):string - Parameter name of parameter #2 changed:
$formatto$associative - Parameter type added for parameter #2 (
$associative):bool - Parameter default value added for position #2 (
$associative):false - Parameter default value added for position #3 (
$context):null
get_headers(
- $url,
+ string $url,
- $format,
+ bool $associative = false,
- $context
+ $context = null
- )
+ ): array|false PHP 7.1
- Optional parameter added - #3:
$context
-get_headers($url, $format)
+get_headers(
+ $url,
+ $format,
+ $context
+ ) get_headers Function Availability
get_headers Function Availability| PHP Version | Availability |
|---|---|
| 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 |