Re: [RFC] PHP Attributes
| From: | Benjamin Eberlei | Date: | Mon, 25 Apr 2016 17:04:26 +0000 |
| Subject: | Re: [RFC] PHP Attributes | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92739@lists.php.net to get a copy of this message | ||
On Mon, Apr 25, 2016 at 6:49 PM, Larry Garfield <larry@garfieldtech.com>
wrote:
> On 04/25/2016 10:20 AM, Dmitry Stogov wrote:
>
>>
>> This leads to some serious copy/paste, highly error prone... =(
>>>
>>
>> If we had a theoretical approach for attribute inheritance, I would
>> implement it.
>> But I wouldn't invite any theory, because anyone is going to depend on
>> use-case.
>>
>
> Realistically, I see only 3 possible approaches to consider:
>
> 1) An overridden class/property/method always inherits its parent's
> annotations/attributes, and you can add to them.
> 2) An overridden class/property/method never inherits its parent's
> annotations/attributes, but you can repeat them.
> 3) Give users a syntactic toggle.
Why do we talk about inheritance at all? ReflectionClass/Method/Property
already have a well defined way of accessing the inherited data. Why should
it work differently for ReflectionAttribute:
Demonstration of how to get access to overwritten doc comments in case of
overwritting a base class:
https://3v4l.org/6fRdn
Attributes should just work exactly the same and we are done.
>
>
> As I said earlier, if you do a call based approach, we could create
>>> @Inherit or @Override, which would not only make us safe from support, but
>>> also gives more power to developers.
>>>
>>
>> If we implement built-in @Inherit and/or @Override, it's not a big
>> problem to copy attributes from parent.
>>
>
> If I understand you correctly, that would be option 3. I would support
> that as well, as it's consistent with how methods work: By default, they
> override the parent method but you can call parent::whatever() to toggle
> the parent behavior back on. Thus, I would suggest that when overriding a
> class/property/method that has annotations, it NOT inherit
> annotations/attributes by default. However, by adding an annotation of
>
> <<__inherit>>
>
> (Or some other internal-reserved keyword, I don't have strong feelings on
> what it is) then the engine will automatically give you all the annotations
> off of the parent, and union them with whatever additional ones you add.
>
> That of course raises interesting questions around interfaces and traits,
> and how annotations on those comingle. Should annotations on interfaces
> auto-apply to their implementations or should they require an explicit
> <<__inherit>>? I'm undecided.
>
> --Larry Garfield
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>