rfc:functional-interfaces
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:functional-interfaces [2016/04/17 18:39] – krakjoe | rfc:functional-interfaces [2016/06/02 05:33] – krakjoe | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Functional Interfaces ====== | ====== PHP RFC: Functional Interfaces ====== | ||
* Version: 0.1 | * Version: 0.1 | ||
- | * Date: 2016-04-17 | + | * Date: 2016-04-17 |
* Author: krakjoe | * Author: krakjoe | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 35: | Line 35: | ||
</ | </ | ||
- | There is enough information in the code above for the compiler | + | There is enough information in the code above for the engine |
The engine generates the appropriate class entry using the closure as the only public method, having easily determined the correct name for that method (there is, and can only be, one possible candidate). | The engine generates the appropriate class entry using the closure as the only public method, having easily determined the correct name for that method (there is, and can only be, one possible candidate). | ||
Line 43: | Line 43: | ||
The code below is not good code, it's not the most efficient version of the code that could exist. It serves to show the difference between implementing a functional interface using a closure, and provides a comparison with anonymous classes: | The code below is not good code, it's not the most efficient version of the code that could exist. It serves to show the difference between implementing a functional interface using a closure, and provides a comparison with anonymous classes: | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 180: | Line 180: | ||
* supports lexical scope | * supports lexical scope | ||
- | Functional | + | Functional |
===== Receiving and Invoking Functional Interfaces ===== | ===== Receiving and Invoking Functional Interfaces ===== | ||
- | The implementation of a functional interface is an instance of Closure, and the interface it was declared to implement, it has the behaviour of both (extends Closure implements Interface): | + | The implementation of a functional interface is an instance of Closure, and the interface it was declared to implement, it has the behaviour of both. |
- | [[https:// | + | The implementation would have the following formal definition: |
+ | |||
+ | < | ||
+ | |||
+ | Such that the following is always true: | ||
+ | |||
+ | < | ||
+ | |||
+ | [[https:// | ||
<code php> | <code php> | ||
Line 214: | Line 222: | ||
</ | </ | ||
- | This means that the receiver (Foo:: | + | This means that the receiver (%%Foo:: |
+ | |||
+ | Both methods of invocation are valid in both receiving and declaring contexts. | ||
===== Error Conditions ===== | ===== Error Conditions ===== | ||
The following conditions will cause compiler errors: | The following conditions will cause compiler errors: | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 232: | Line 242: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: cannot implement non functional interface IFoo in /in/65W6i on line 7 | + | |
- | </ | + | |
//Reason: IFoo cannot be considered a functional interface, because it contains more than one abstract method.// | //Reason: IFoo cannot be considered a functional interface, because it contains more than one abstract method.// | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 252: | Line 260: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: cannot implement non functional interface IBar in /in/qLbPv on line 9 | + | |
- | </ | + | |
//Reason: Although IBar only declares one abstract method, it extends IFoo and so contains two abstract methods// | //Reason: Although IBar only declares one abstract method, it extends IFoo and so contains two abstract methods// | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 269: | Line 275: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: cannot implement non interface Foo in /in/WT98N on line 6 | + | |
- | </ | + | |
//Reason: Although Foo contains only one abstract method, it is not an interface// | //Reason: Although Foo contains only one abstract method, it is not an interface// | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 286: | Line 290: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: functional interface cannot implement self in /in/MMuD0 on line 4 | + | |
- | </ | + | |
//Reason: Although self is a valid scope in that context, self, parent, and static, can never be interfaces// | //Reason: Although self is a valid scope in that context, self, parent, and static, can never be interfaces// | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 303: | Line 305: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: cannot create non static implementation of static functional interface IFoo in /in/2AiUV on line 6 | + | |
- | </ | + | |
//Reason: The compiler would raise less specific errors later on// | //Reason: The compiler would raise less specific errors later on// | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 320: | Line 320: | ||
</ | </ | ||
- | < | + | < |
- | Fatal error: cannot create static implementation of non static functional interface IFoo in /in/o9gIB on line 6 | + | |
- | </ | + | |
//Reason: The compiler would raise less specific errors later on// | //Reason: The compiler would raise less specific errors later on// | ||
+ | |||
+ | ===== Syntax Choices ===== | ||
+ | |||
+ | Interface and return type reversed: | ||
+ | |||
+ | < | ||
+ | |||
+ | It looks as if '' | ||
+ | |||
+ | Interface before arguments: | ||
+ | |||
+ | < | ||
+ | |||
+ | The arguments list looks as if it somehow applies to '' | ||
+ | |||
+ | Interface after arguments and before use: | ||
+ | |||
+ | < | ||
+ | |||
+ | This looks as if '' | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | Voting started on May 15th, ends May 29th 2016. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 335: | Line 362: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Extensions will be able to provide | + | The API to create functional interface |
==== To Opcache ==== | ==== To Opcache ==== | ||
Opcache may need a trivial patching. | Opcache may need a trivial patching. | ||
- | |||
- | ===== Open Issues ===== | ||
- | TBD | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | + | When the concept of functional interfaces is implemented, |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 358: | Line 382: | ||
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | |
+ | [[http:// |
rfc/functional-interfaces.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1