Skip to content

Should $http_response_header be deprecated? #19651

@campbell-m

Description

@campbell-m

Description

The following code:

<?php
declare(strict_types=1);

error_reporting(-1);
ini_set('display_errors', '1');

echo PHP_VERSION . "<br>\n";

function get_contents() {
  file_get_contents("https://www.php.net/manual/en/reserved.variables.httpresponseheader.php");
  $headers = $http_response_header;
  var_dump($headers);
}

get_contents();

Resulted in this output:

8.5.0beta2
array(12) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(17) "Server: myracloud" [2]=> string(35) "Date: Sun, 31 Aug 2025 07:39:53 GMT" [3]=> string(38) "Content-Type: text/html; charset=utf-8" [4]=> string(17) "Connection: close" [5]=> string(20) "Content-language: en" [6]=> string(38) "Permissions-Policy: interest-cohort=()" [7]=> string(27) "X-Frame-Options: SAMEORIGIN" [8]=> string(93) "Link: ; rel=shorturl" [9]=> string(44) "Last-Modified: Sun, 31 Aug 2025 06:00:41 GMT" [10]=> string(38) "Expires: Sun, 31 Aug 2025 07:39:53 GMT" [11]=> string(24) "Cache-Control: max-age=0" }

But I expected this output instead:

8.5.0beta2
Deprecated: The predefined locally scoped $http_response_header variable is deprecated, call http_get_last_response_headers() instead in C:\inetpub\wwwroot\... on line ...
array(12) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(17) "Server: myracloud" [2]=> string(35) "Date: Sun, 31 Aug 2025 07:39:53 GMT" [3]=> string(38) "Content-Type: text/html; charset=utf-8" [4]=> string(17) "Connection: close" [5]=> string(20) "Content-language: en" [6]=> string(38) "Permissions-Policy: interest-cohort=()" [7]=> string(27) "X-Frame-Options: SAMEORIGIN" [8]=> string(93) "Link: ; rel=shorturl" [9]=> string(44) "Last-Modified: Sun, 31 Aug 2025 06:00:41 GMT" [10]=> string(38) "Expires: Sun, 31 Aug 2025 07:39:53 GMT" [11]=> string(24) "Cache-Control: max-age=0" }

I have been testing PHP 8.5.0beta2 on Windows and have occasionally been getting the message "Deprecated: The predefined locally scoped $http_response_header variable is deprecated, call http_get_last_response_headers() instead in ...". However, I couldn't reproduce it reliably and wrote the small test program above, expecting to get the deprecation message, but didn't.

PHP Version

PHP Version 8.5.0beta2

Operating System

Microsoft-IIS/10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions