Reflection*::hasAttribute()
| From: | Robin Chalas | Date: | Wed, 12 Jul 2023 03:25:46 +0000 |
| Subject: | Reflection*::hasAttribute() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120790@lists.php.net to get a copy of this message | ||
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
Robin Chalas
Principal Engineer @Les-Tilleuls.coop
03 66 72 43 94
robin@les-tilleuls.coop
82 Rue Winston Churchill - 59160 Lomme