RFC: Add Reflection*::hasAttribute()
| From: | Robin Chalas | Date: | Wed, 12 Jul 2023 04:00:40 +0000 |
| Subject: | RFC: Add Reflection*::hasAttribute() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120791@lists.php.net to get a copy of this message | ||
Hi internals,
It is common for attributes to be used as markers, and just like a marker interface has 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 attributes 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, would I need to submit an RFC or would a pull request on php-src 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
—
Robin Chalas