You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]
privatestring$property;
#[Tag]
privatestring$otherProperty;
privatestring$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?
The text was updated successfully, but these errors were encountered:
This is possible, but ofc we wouldn't want to couple this API tightly to properties. Something like getTarget would be possible. One downside is that this strong reference to the target will prevent garbage collection to it, so it you just need to hold on to the attribute reflection itself, memory will slightly increase. But this is likely negligible. Otherwise, this should not be hard to implement. /cc @DanielEScherzer
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: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?
The text was updated successfully, but these errors were encountered: