Re: RFC: Trait expects interface

From: Date: Mon, 17 Jan 2022 18:03:52 +0000
Subject: Re: RFC: Trait expects interface
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-116888@lists.php.net to get a copy of this message
> On Jan 7, 2022, at 1:56 PM, Rowan Tommins <rowan.collins@gmail.com> wrote: > > On 07/01/2022 13:47, Robert Korulczyk wrote: >> I'm not really sure why would you not want this - what is the point of marking method >> as interface implementation, if it is not reflected by type system in actual execution? > > > It's really quite simple: I don't want traits to tell me how I "must" use > them, but am quite happy for them to document how I "can" use them. About any of these someone could say "I don't want to be told..." "...I must implement an abstract method" "...I must implement all the methods in an interface" "...I must pass all arguments declared in a function" "...I must pass arguments that are of the type that were type-hinted" "...I cannot extend a final class" "...I cannot access a private property outside the class" "...I cannot change a readonly property after it has been initialized" And yet specifying appropriate constraints for a specific use-case has its benefits. I'm sure you can see benefit to the above constraints so it is strange to me you cannot see the benefit of traits that would constrain their uses to requiring an interface. If it were possible to specify that a trait required an interface then I don't envision anyone other than those who need bespoke traits would do so, and those are not likely traits you would want to use anyway because they could be changed by the developer when their use-case evolved. #jmtcw #fwiw -Mike > > Unless we allow a trait to *automatically* implement the interface (or similar features, such > as an interface with default implementation) there is no direct impact on the actual type system. > There are, as far as I can see, three things the feature would provide: > > - Documentation: the trait can tell me as a programmer that it contains everything I need to > implement a particular interface > - Code generation: the trait can import the list of methods from an interface as abstract > methods which it requires > - Policing: the trait can force me as a programmer to use it in a certain way; this is the part > I don't see the need for > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >

« previous php.internals (#116888) next »