rfc:traits-with-interfaces

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:traits-with-interfaces [2016/02/18 21:10] – v 0.2, splitting into two proposals kevingessnerrfc:traits-with-interfaces [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 50: Line 50:
 //This proposal depends on Proposal 1, above.// //This proposal depends on Proposal 1, above.//
  
-A trait that implements an interface provides methods that fulfill the interface’s contract.  When a class inserts that trait, the class now fulfills the interface, but the class explicitly specify that it implements the interface.  This second proposal is that any class, by inserting a trait that implements an interface, would implicitly be declared to implement that interface.  The class need not repeat the interface declaration.+A trait that implements an interface provides methods that fulfill the interface’s contract.  When a class inserts that trait, the class now fulfills the interface, but the class must explicitly specify that it implements the interface.  This second proposal is that any class, by inserting a trait that implements an interface, would implicitly be declared to implement that interface.  The class need not repeat the interface declaration.
  
 Concretely, Proposal 2 makes this code be valid and functional: Concretely, Proposal 2 makes this code be valid and functional:
Line 77: Line 77:
 Classes that insert the trait may override any members (as with existing traits) and continue to implement the interface.  Other classes need not be aware that a class implements an interface via a trait or directly, in the same way they need not be aware if an interface is inherited by a class. Classes that insert the trait may override any members (as with existing traits) and continue to implement the interface.  Other classes need not be aware that a class implements an interface via a trait or directly, in the same way they need not be aware if an interface is inherited by a class.
  
-This change reduces the overhead of implementing an interface via a trait, because a class will only need to implement the trait, not also explicitly specify the interface.+This change reduces the overhead of implementing an interface via a trait, because a class will only need to insert the trait, not also explicitly declare the interface.
  
 Other languages that implement languages features like PHP’s traits allow for interface specifications like this RFC.  See “References” for links. Other languages that implement languages features like PHP’s traits allow for interface specifications like this RFC.  See “References” for links.
Line 269: Line 269:
 Language spec patch, covering Proposal 1: https://github.com/php/php-langspec/compare/master...kevingessner:traits-with-interfaces Language spec patch, covering Proposal 1: https://github.com/php/php-langspec/compare/master...kevingessner:traits-with-interfaces
  
-Other patches TBD.+php-src patch implementing Proposal 1: https://github.com/php/php-src/pull/1773
  
 ===== Implementation ===== ===== Implementation =====
rfc/traits-with-interfaces.1455829820.txt.gz · Last modified: 2017/09/22 13:28 (external edit)