Dereferencing an array in foreach unwraps the reference
未关闭
还没有人认领这个 Issue。
Bug
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code (https://3v4l.org/8QBeN):
<?php
$a = [1];
foreach ((isset($a["key"]) ? [&$a["key"]] : [&$a])[0] as &$v) {
var_dump($a);
$v++;
}
var_dump($a);
Resulted in this output:
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
But I expected this output instead:
array(1) {
[0]=>
&int(1)
}
array(1) {
[0]=>
&int(2)
}
In PHP 7.2 and before, the output was as expected. Today it's required to use an explicit variable to preserve the reference.
PHP Version
PHP 7.3.0 - master
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中链接的 PHP 复现代码开始,比较其在 PHP 7.2 和报告的 PHP 7.3 版本之间的行为。调查在迭代条件数组表达式时如何处理 foreach 引用。完成的标准是引用得到保留,且输出与预期结果一致,无需显式的临时变量。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100