Enum case as Array key?
未关闭
还没有人认领这个 Issue。
Feature
Status: Requires RFC
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Before enum exist, i used constant to define the array key. Now i want to use enum. But i got error when i declare the enum as array key. so i do the workaround like this:
if (!function_exists('_api')) {
/**
* use enum as Array Key.
*
* @param array $values
* @param \App\Enums\Api\ResponseKey $key
* @param mixed $data
* @return array
*/
function _api(?array &$values, ResponseKey $key, $data)
{
if (! is_array($values)) $values = [];
$values[$key->value] = $data;
return $values;
}
}
Then call it like _api($data, ResponseKey::message, "success");
Can this workaround can be implemented as feature for future PHP?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
未指定任何文件或测试。首先阅读 issue 讨论并检查 PHP enum 和 array-key 的行为,然后找到相关的语言实现和回归测试。完成这项工作需要达成一致的语言设计,并实现对预期 enum 键行为的覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100