"Attempting to set reference to non referenceable value" upon array destructuring by reference
オープン
まだ誰も着手していません。
Bug
Category: Engine
Status: Needs Triage
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.1k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
Description
The following code:
<?php
$someglobal = 1;
function foo() {
global $someglobal;
return [&$someglobal];
}
list(&$ref) = foo();
++$ref;
var_dump($someglobal);
Resulted in this output:
Notice: Attempting to set reference to non referenceable value in /tmp/preview on line 10
int(1)
But I expected this output instead:
int(2)
Making foo return by reference silences this warning, i.e. this is a valid workaround:
function &foo() {
global $someglobal;
$ref = [&$someglobal];
return $ref;
}
But actually, the array itself should not need to return by reference, if we only desire to access a by-reference value within the array.
On top of this, this simple code:
<?php
[&$a] = [&$b];
emits Fatal error: Cannot assign reference to non referenceable value.
PHP Version
PHP 7.3-8.3
Operating System
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PHP 7.3–8.3 で 2 つの分割代入の例を再現し、それぞれの警告、fatal error、出力を報告された期待値と比較します。完了条件は、1 つ目の例が notice を出さずにグローバルの値を int(2) にインクリメントし、2 つ目の例が参照による代入の fatal error を出さなくなることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100