Overtrue\Http\Support\Collection::dotGet()方法无法正确获取“.”号分割的key
还没有人认领这个 Issue。
评估
调研方向
Start by reading src/Support/Collection.php and locating dotGet(), whose implementation and missing return are shown in the issue. Check how the collection's get('b.b1') call reaches this method; done means the dotted lookup returns the nested value instead of null.
由索引模型根据 Issue 内容生成。
描述
版本:1.2.3
文件:src/Support/Collection.php
PHP版本:8.1
问题描述:
一个形如:
$config = new Collection([
'a' => 'a0',
'b' => [
'b1' => 'b10'
]
]);
var_dump($config->get('b.b1')); //result is "null"
原因:
/**
* @param array $array
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
public function dotGet($array, $key, $default = null)
{
if (is_null($key)) {
return $array;
}
if (array_key_exists($key, $array)) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (array_key_exists($segment, $array)) {
$array = $array[$segment];
} else {
return $default;
}
}
// 缺少循环完的返回 return $array;
}
- 主要语言
- PHP
- 星标
- 125
- 派生
- 17
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
v3
难度 2/5 1-3 小时 新手友好度 88/100
pluginkollektiv/antispam-bee#952 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
-
has-image has-readme needs-attention new-tool repo-verified
难度 2/5 1-3 小时 新手友好度 68/100
shanselman/TinyToolTown#974 · 1 条评论 ·
维护者通常 2 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复