On Wed, Jul 12, 2023, at 3:25 AM, Robin Chalas wrote:
> Hi internals,
>
> It is common attributes to be used as markers. Just like a marker 
> interface with no methods, such attributes don’t have any parameter.
>
> Examples from Symfony:
> - #[Ignore] indicating that a property should be skipped in a 
> serialization contextl
> - #[Exclude] telling the dependency injection container that a given 
> class should be skipped from automatic service registration
>
>
> From Doctrine ORM:
> - #[Id] to tell which property of en entity class should be mapped as 
> primary key
>
> Those are meant to opt in/out some behavior through detection only. But 
> with the current API, such code needs to call `getAttributes()` while 
> it doesn't care about the returned ReflectionAttribute instances.
> Hence I’m wondering if we could add a `hasAttribute()` method to the 
> reflectors that are targetable by attributes.
>
> Does that make sense?
> If it does, do I need to open an RFC for that feature or is a pull 
> request be enough?
>
> Anyway, I’d be happy to work on the implementation as a first 
> contribution to PHP.
> Looking forward to your feedback.
>
> Thanks.
> Robin

I think that would require an RFC.

To clarify, you're proposing to replace this:

count((new ReflectionClass(Beep::class))->getAttributes(Ignore::class)) == true

with

(new ReflectionClass(Beep::class))->hasAttribute(Ignore::class)

Right?  That doesn't seem like a huge improvement.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to