file_get_contents should probably clear the global state of last headers
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
Description
The following code:
<?php
file_get_contents(__FILE__);
var_dump(http_get_last_response_headers());
file_get_contents('https://php.net/');
var_dump(http_get_last_response_headers());
file_get_contents(__FILE__);
var_dump(http_get_last_response_headers());
Resulted in this output:
NULL
array( headers from php.net )
array( headers from php.net )
But I expected this output instead:
NULL
array( headers from php.net )
NULL // as reading a file clearly outputs no headers
IMO this is very surprising, and can lead to bugs (see https://github.com/jsonrainbow/json-schema/pull/843 for example) as people are now nudged to switch to http_get_last_response_headers() by the deprecations.
The problem is that $http_response_headers, while a very ugly API, was a local variable.. and http_get_last_response_headers() while appearing cleaner stores global state and can thus leak data across boundaries if you do not call http_clear_last_response_headers() after fetching the headers.
Thus my suggestion would be that file_get_contents first clears the headers and then populates them if the stream wrapper in use has anything to populate.
/cc @Girgias as I know you were involved in the deprecation. And apologies if this was already discussed somewhere I didn't find.
PHP Version
All versions where `http_get_last_response_headers()` is available
Operating System
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue の PHP 再現コードを実行し、file_get_contents()、http_get_last_response_headers()、http_clear_last_response_headers() の実装を読みます。ストリームラッパーが保存されているヘッダーをどのように更新するかを追跡し、以前の HTTP リクエストが残したヘッダーをローカルファイルの読み取りがクリアすることを示すテストカバレッジを追加します。完了条件は、最後の呼び出しが NULL を返すことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, php
- 領域
- backend-api-design
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100