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