Bug #75893 [Opn->Csd]: file_get_contents $http_response_header variable bugged with opcache

From: Date: Mon, 05 Feb 2018 20:44:11 +0000
Subject: Bug #75893 [Opn->Csd]: file_get_contents $http_response_header variable bugged with opcache
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213822@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75893&edit=1 ID: 75893 Updated by: nikic@php.net Reported by: rla at systime dot dk Summary: file_get_contents $http_response_header variable bugged with opcache -Status: Open +Status: Closed Type: Bug Package: opcache Operating System: Ubuntu Linux 16.04 PHP Version: 7.2.1 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2018-01-31 12:22:55] 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! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75893&edit=1

« previous php.bugs (#213822) next »