Possible regression with spreading nested arrays into a function call and references
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.2k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
I've noticed the following possible regression:
$args = [1];
$ref = [&$args];
function test(&$v) {
$v = 7;
};
test(...$ref[0]);
var_dump($args[0]);
Starting with PHP 7.3, the output of the above code has changed:
$ docker run --rm php:7.2.34 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);"
int(7)
$ docker run --rm php:7.3 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);"
int(1)
$ docker run --rm php:8.3.7 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);"
int(1)
The only entry I've found within PHP 7.3's release notes that might be related is References returned by Array and Property Accesses are immediately unwrapped. But I'm not sure whether this does actually describe the behavior change in the code snippet above.
I'm also not really sure whether the code is valid or not. In case it is not, it might be helpful to display a message.
There exists a workaround to get the old result by introducing another variable:
$temp = &$ref[0];
test(...$temp);
PHP Version
PHP 7.3.0 - PHP 8.3.7
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
Comienza reproduciendo el ejemplo de expansión de arrays anidados y referencias en PHP 7.2, 7.3 y 8.3, y compáralo después con la nota de migración sobre la eliminación de referencias de PHP 7.3. Determina si el resultado cambiado es válido; se considera terminado cuando se documenta la semántica esperada y se añade una corrección o un diagnóstico si el comportamiento es erróneo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100