Possible regression with spreading nested arrays into a function call and references
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.1k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PHP 7.2、7.3、8.3 でネストした配列のスプレッドと参照の例を再現し、その後、PHP 7.3 の参照のアンラップに関する移行ノートと比較します。変更された結果が有効かどうかを判断します。完了条件は、期待されるセマンティクスを文書化し、動作が誤っている場合に修正または診断を追加することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100