|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75893 file_get_contents $http_response_header variable bugged with opcache
Submitted: 2018-01-31 12:22 UTC Modified: -
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rla at systime dot dk Assigned:
Status: Closed Package: opcache
PHP Version: 7.2.1 OS: Ubuntu Linux 16.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
39 - 30 = ?
Subscribe to this entry?

 [2018-01-31 12:22 UTC] rla at systime dot dk
The issue:

When using file_get_contents to request an http URL a magical $http_response_header variable is set in the local context. This variable (array) works as expected when accessed directly, but if we assign it to a temporary variable ($status_code_string in the example), the value is lost.


This issue only happens when the opcache is enabled (eg. opcache.enable = 1 and opcache.enable_cli=1 for cli testing). The bug itself was discovered in php-fpm, but providing a demonstration for that is more tricky.
I'm unsure of exactly how it's possible, but the issue only seems to trigger on the second run.

The issue is present in PHP 7.2.1.
The issue does not seem to be present in PHP 7.2.0.
The issue is not present in PHP 7.1.13.

Test script:

class debug
    public static function bug()

	$url = '';
	$response = file_get_contents($url);
	$status_code_string = $http_response_header[0];
	print('indirect ' . $status_code_string . "\n");
	print('direct ' . $http_response_header[0] . "\n");
	print(is_null($http_response_header[0]) . "\n");
	print(is_null($status_code_string) . "\n");

$debug = new debug();

Expected result:
The $status_code_string variable should be equivalent to $http_response_header[0].

Neither of the variables should return true for is_null.

Actual result:
Only $http_response_header[0] contains the expected response.

Both variables return true for is_null!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-05 20:44 UTC]
Automatic comment on behalf of
Log: Fixed bug #75893
 [2018-02-05 20:44 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 00:01:28 2024 UTC