Bug #75893 [NEW]: file_get_contents $http_response_header variable bugged with opcache
| From: | rla at systime dot dk | Date: | Wed, 31 Jan 2018 12:22:59 +0000 |
| Subject: | Bug #75893 [NEW]: file_get_contents $http_response_header variable bugged with opcache | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213760@lists.php.net to get a copy of this message | ||
From: rla at systime dot dk
Operating system: Ubuntu Linux 16.04
PHP version: 7.2.1
Package: opcache
Bug Type: Bug
Bug description:file_get_contents $http_response_header variable bugged with opcache
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 bug report at https://bugs.php.net/bug.php?id=75893&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75893&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75893&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75893&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75893&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75893&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75893&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75893&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75893&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75893&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75893&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75893&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75893&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75893&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75893&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75893&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75893&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75893&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75893&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75893&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75893&r=mysqlcfg