file_get_contents should probably clear the global state of last headers
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.1k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza ejecutando la reproducción en PHP del issue y leyendo las implementaciones de file_get_contents(), http_get_last_response_headers() y http_clear_last_response_headers(). Sigue cómo los wrappers de streams actualizan las cabeceras almacenadas y añade cobertura que demuestre que la lectura de un archivo local borra las cabeceras dejadas por una solicitud HTTP anterior; se considera terminado cuando la llamada final devuelve NULL.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, php
- Área
- backend-api-design
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 48/100