rfc:functional-interfaces
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:functional-interfaces [2016/04/17 19:20] – krakjoe | rfc:functional-interfaces [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
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 ===== | ||
Line 188: | Line 188: | ||
The implementation would have the following formal definition: | The implementation would have the following formal definition: | ||
- | < | + | < |
- | class {Interface}\0{closure} extends Closure implements Interface | + | |
- | </ | + | |
Such that the following is always true: | Such that the following is always true: | ||
- | '' | + | < |
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 224: | 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. | Both methods of invocation are valid in both receiving and declaring contexts. | ||
Line 231: | Line 229: | ||
The following conditions will cause compiler errors: | The following conditions will cause compiler errors: | ||
- | [[https:// | + | [[https:// |
<code php> | <code php> | ||
Line 248: | Line 246: | ||
//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 266: | Line 264: | ||
//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 281: | Line 279: | ||
//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> | ||
- | ... | + | <?php |
- | function () implements self {}; | + | new class { |
- | ... | + | |
+ | | ||
+ | } | ||
+ | }; | ||
</ | </ | ||
- | |||
- | **See 3v4l for this example, the wiki has problems displaying the code.** | ||
< | < | ||
Line 295: | Line 294: | ||
//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 310: | Line 309: | ||
//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 324: | Line 323: | ||
//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, ended May 29th 2016. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 334: | 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 357: | Line 382: | ||
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | |
+ | [[http:// |
rfc/functional-interfaces.1460920841.txt.gz · Last modified: 2017/09/22 13:28 (external edit)