The predefined locally scoped $http_response_header variable is deprecated, call http_get_last_response_headers() instead

Description

The PHP variable $http_response_header is automagically created after a call to a remote resource. It contains the returned headers, for further analysis. This variable is deprecated since PHP 8.5, and will disappear in PHP 9.0. It should be replaced with a call to http_get_last_response_headers().

Example

<?php

    file_get_contents(https://www.php.net/);
    var_dump($http_response_header); // variable is populated in the local scope

?>

Solutions

  • Call http_get_last_response_headers() instead of relying on the variable.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See http_response_header.

Static Analysis

This error may be tracked down with the following static analysis rules: Php/HttpResponseHeaderIsDeprecated.