Possible regression with spreading nested arrays into a function call and references
Nessuno ha ancora preso questa issue.
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.1k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l’esempio di espansione di array annidati e riferimenti su PHP 7.2, 7.3 e 8.3, quindi confrontalo con la nota di migrazione di PHP 7.3 sulla rimozione dei riferimenti. Determina se il risultato modificato è valido; il lavoro è completo quando la semantica prevista è documentata e viene aggiunta una correzione o una diagnostica se il comportamento è errato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100