Re: Traits with interfaces

From: Date: Sun, 04 Mar 2018 22:32:04 +0000
Subject: Re: Traits with interfaces
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-101954@lists.php.net to get a copy of this message
On 2 March 2018 01:38:37 GMT+00:00, "Pedro Magalhães" <mail@pmmaga.net> wrote: >On Thu, Mar 1, 2018 at 11:04 PM, Rowan Collins ><rowan.collins@gmail.com> >wrote: >> >> What *can* break an interface's contract is changing the *visibility* >of >> the pasted method using "as protected" or "as private". This would >need to >> be captured somehow while composing the class, probably producing a >> compile-time error, just as an explicit "implements" declaration >would. > > >To add to that, the receiving class can simply replace the trait >method. True. This feels closer to normal interface / inheritance checks though: you've explicitly written a method that violates the contract not used a trait-specific syntax or feature to do so. >Currently, not even an abstract method on a trait enforces anything on >the >receiving class. See: https://bugs.php.net/bug.php?id=75449 The way I see it, the Trait in this proposal isn't enforcing anything, it's just pasting in the "implements Foo" clause along with the extra methods. Whether the result is valid is up to the receiving class, and there's a completely separate requirement that the Trait itself matches the contract. >With that said, I have started some work on "Implicit Interfaces". I'm not sure I like the sound of this, but I'll leave that to its own thread. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#101954) next »