Re: Interface for reflection entities who implements getAttributes method
| From: | Andreas Hennings | Date: | Thu, 03 Mar 2022 18:42:06 +0000 |
| Subject: | Re: Interface for reflection entities who implements getAttributes method | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117252@lists.php.net to get a copy of this message | ||
Hello list.
Another potential benefit of such interfaces can be polyfills.
PHP 8.x: class ReflectionClass implements Reflector, AttributesHaving {..}
PHP 7.x. class UserlandReflectionClass extends ReflectionClass
implements AttributesHaving {..}
function f(AttributesHaving $reflector) {
$attributes = $reflector->getAttributes();
...
}
I wonder if it should be called "AttributeReflector" or
"AttributesHaving" or "AbleToHaveAttributesBeing" :)
On Fri, 25 Feb 2022 at 23:58, DANIEL VARGAS MUCCILLO
<daniel.muccillo@ufsm.br> wrote:
>
> Hi Internals, hope you are all well.
>
> I've been playing around with Attributes and found that the only
> way for safely type hint for reflection entities who implement the
> getAttributes method is the following union:
>
>
> ReflectionClass|ReflectionClassConstant|ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty
> > $reflectionEntity
>
>
> For a single use case this was ok, but i would like to survey if
> people here would be interested in the introduction of a interface
> against which we could correctly ensure, with less effort, that
> getAttribute is available.
>
> I believe that it would be something along the lines of:
>
> > interface AttributeReflector {
>
> public function getAttributes(?string $name = null, int $flags = 0):
> > array;
>
> }
>
>
> I have no experience with the PHP's source code, but if you think
> that it's a good idea I would like to propose an RFC along with a PoC
> patch to make this adition.
>
> Thanks for your time until now and all the good work I've seen here.
>
> --
> Daniel Vargas Muccillo