Connect attributes to their targets
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the attribute reflection behavior around getTarget() and the proposed getPropertyReflection() API, alongside ReflectionProperty's existing class and property relationship. Determine whether property attributes should expose their declaring class and property or a broader target object. Done means an agreed API design with corresponding behavior and tests for the example involving multiple properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100