php / php/php-src

Connect attributes to their targets

オープン
#18,553 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: reflection Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 15時間
マージ済み PR(30日)
103

説明

Description

There currently seems to be no way to get the actual target of the attribute. The getTarget method returns the bitmask of the constants. Example usage:

class X {

#[Tag]
private string $property;

#[Tag]
private string $otherProperty;

private string $extraProperty;
}

...
$attributeReflections = $propertyReflection->getAttributes(Tag::class);
// now I want to pass the reflections somewhere else and do

$property = $attributeReflection->getPropertyReflection();
$property->getValue();

Obviously there is a workaround to build some datastructure to pass the reference in along with the reflection. But it seems like it should be part of the API. Given I can limit to what type of object I can attach it to, I should be able to get the actual "instance" of the object somehow IMHO. But maybe I'm missing some important context why this doesn't make sense, sorry if that's the case :)

Essentially it's the same as when ReflectionProperty has $class even though one could argue that you always get the property from class, so you should be able to maintain the relation yourself. I believe that property attribute should at least have $class and $property, if the above proposed API is too heavy.

Does it make sense?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、getTarget() 周辺の属性リフレクションの動作と、提案されている getPropertyReflection() API を、ReflectionProperty に既に存在するクラスとプロパティの関係と併せて確認します。プロパティ属性が宣言元のクラスとプロパティを公開すべきか、それともより広い対象オブジェクトを公開すべきかを判断します。複数のプロパティを含む例について、対応する動作とテストを備えた合意済みの API 設計ができれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。