On Wed, Feb 24, 2016 at 4:46 PM Kevin Gessner <kgess...@etsy.com> wrote:

> On Tue, Feb 23, 2016 at 4:48 AM, Chris Riley <t.carn...@gmail.com> wrote:
>
> > This isn't such a great idea as it will cause some of traits
> functionality
> > to be broken: I can currently use a trait and alias its methods and
> change
> > their visibility. If a trait implements an interface which is copied onto
> > my class I can no longer do this as the compiler will throw a fatal error
> > for the class not correctly implementing the interface that got copied
> from
> > the trait.
> >
>
> This is only true under Proposal 2 of the RFC, and this is listed as an
> open issue: https://wiki.php.net/rfc/traits-with-interfaces#proposal_2
>
> Proposal 1, where the engine enforces interface declarations on traits,
> doesn't affect how traits are inserted and still allows aliasing.
>
>
> > If you decide to continue pursuing this RFC, I'd like to see some thought
> > given to the above; perhaps it could be as simple as not copying the
> > interface if aliases/visibility changes are made in the use or perhaps
> > something more complex which allows specifying which interfaces should be
> > copied into the class from the trait.
> >
>
> I agree that there are several reasonable solutions here, but I'm not sure
> which is the best.  It does feel too aggressive to have it be a fatal error
> if aliasing undoes the interface implementation.  At the same time,
> introducing new syntax to enable aliasing to work with interface
> propagation defeats the purpose, which is to make it easier and simpler to
> implement an interface via a trait.
>
> I'd be interested to hear if you have any ideas about how this should
> look.  I'm mostly unfamiliar with aliasing traits in practice, so I'd be
> curious to see how this RFC would affect your code.
>
> Since the class doesn't know you are using the trait to implement the
interface, if you alias the trait method, then the class no longer
implements the interface unless it defines the method that is now missing
itself.

Remember, the contents of the trait are just getting copy/pasted into the
class. If you alias a method, then the method gets pasted in using the
alias, not the original name.

That being said, it should be rare that you would alias a method and then
not implement the method yourself - as the need to redefine/expand on its
functionality is the reason you usually alias a trait method.



> Cheers
> -- Kevin
>
-- 
-- Chase
chasepee...@gmail.com

Reply via email to