php / php/php-src

Add additional methods for reflections that have attributes

未关闭
#8,489 16 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Extension: reflection Feature Status: Verified
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

All currently attributable reflections have a single method relating to attributes.

getAttributes(?string $name = null, int $flags = 0): array

Additional methods for dealing with attributes would be a nice improvement and would simplify common approaches. I'm proposing the following methods.

getAttribute

Get a single instance of ReflectionAttribute, following the same rules as getAttributes, minus the fact that $name is required.

getAttribute(string $name, int $flags = 0): ?ReflectionAttribute

If more than one attribute matches, an exception should be thrown.

hasAttribute

Functionally identical to getAttribute, except it will return true if one or more matches are found, otherwise it returns false.

hasAttribute(string $name, int $flags = 0): bool

getNumberOfAttributes

Again, follows the same rules as getAttributes, but will return the number found. This particular method is based on the ReflectionFunctionAbstract::getNumberOfParameters method.

getNumberOfAttributes(?string $name = null, int $flags = 0): int

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先定位可附加属性的反射对象现有的 getAttributes 实现,以及相关的 ReflectionAttribute 测试。以 ReflectionFunctionAbstract::getNumberOfParameters 作为参考先例,然后针对所有可附加属性的反射类型,验证所提议方法的匹配、flags、重复项处理和返回值。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
api, backend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。