php.net |  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: -
Votes:1
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
 [2018-01-31 12:22 UTC] rla at systime dot dk
Description:
------------
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.

Preconditions:

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:
---------------
<?php

class debug
{
    public static function bug()
    {

	$url = 'http://php.net';
	$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();
$debug::bug();

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!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-05 20:44 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1391a0fa0b41409296efc39c454400073418d9fb
Log: Fixed bug #75893
 [2018-02-05 20:44 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 05:01:28 2024 UTC