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.mucci...@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

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

Reply via email to