Bug #71245 [NEW]: file_get_contents() ignores "header" context option if it's a reference

From: Date: Wed, 30 Dec 2015 11:09:30 +0000
Subject: Bug #71245 [NEW]: file_get_contents() ignores "header" context option if it's a reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198311@lists.php.net to get a copy of this message
From: php at maisqi dot com Operating system: Windows 64 bits PHP version: 7.0.1 Package: Streams related Bug Type: Bug Bug description:file_get_contents() ignores "header" context option if it's a reference Description: ------------ file_get_contents() does not pass the headers in the stream context if it's given as a reference to an array, as exemplified below: $headers = ['Host: maisqi.com']; $httpContext = [ 'http' => [ 'header' => &$headers, ], ]; $uri = 'http://77.91.206.217/outros/bugs/php/_print_host_headers.php'; $content = file_get_contents($uri, false, stream_context_create($httpContext)); In PHP 5.6, this works flawlessly; on PHP7, the request is issued with no headers. If no reference is given ('header' => $headers), this works on both versions. Test script: --------------- $headers = ['Host: maisqi.com']; $httpContext = [ 'http' => [ 'protocol_version' => '1.1', 'method' => 'GET', 'header' => &$headers, 'follow_location' => 0, 'max_redirects' => 0, 'ignore_errors' => true, 'timeout' => 60, ], ]; $uri = 'http://77.91.206.217/outros/bugs/php/_print_host_headers.php'; $content = file_get_contents($uri, false, stream_context_create($httpContext)); echo "Content:\n"; if ($content === false) echo '-'; else if ($content === '') echo '(empty)'; else echo htmlspecialchars($content); echo "\n\n\$http_response_header:\n"; if (empty($http_response_header)) echo '-'; else print_r($http_response_header); Expected result: ---------------- It should print something like tbis: Content: HTTP_HOST: maisqi.com SERVER_NAME: maisqi.com $http_response_header: Array ( [0] => HTTP/1.1 200 OK [1] => Date: Wed, 30 Dec 2015 11:04:09 GMT [2] => Server: Apache [3] => Connection: close [4] => Content-Type: text/html; charset=utf-8 ) Actual result: -------------- It prints the HTML of a "Page Not Found" page, because no specific Host header is requested. -- Edit bug report at https://bugs.php.net/bug.php?id=71245&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71245&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71245&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71245&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71245&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71245&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71245&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71245&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71245&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71245&r=support Expected behavior: https://bugs.php.net/fix.php?id=71245&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71245&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71245&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71245&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71245&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71245&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71245&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71245&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71245&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71245&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71245&r=mysqlcfg

« previous php.bugs (#198311) next »