rfc:allow-void-variance
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:allow-void-variance [2019/02/04 02:16] – created wesnetmo | rfc:allow-void-variance [2019/02/04 06:39] – wesnetmo | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: Allow void return type variance |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2019-02-04 | * Date: 2019-02-04 | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes to change | + | This RFC proposes to change |
===== Rationale ===== | ===== Rationale ===== | ||
- | The intent of ''' | + | **The intent of '' |
- | Currently, it also denies | + | It shouldn' |
<code php> | <code php> | ||
- | <?php | ||
- | |||
class Foo{ | class Foo{ | ||
function method (): void {} | function method (): void {} | ||
Line 32: | Line 30: | ||
</ | </ | ||
- | This should be allowed, because it is causing | + | This should be allowed because it is causing discontent |
<code php> | <code php> | ||
function myFooConsumer (Foo $foo) { | function myFooConsumer (Foo $foo) { | ||
- | // method() is void, therefore we shouldn't be using its return | + | // method() is void, therefore we won't be using its return |
| | ||
Line 43: | Line 41: | ||
</ | </ | ||
- | If a ''' | + | If a '' |
- | it is not breaking the code in ''' | + | it is not breaking the code in '' |
- | ''' | + | '' |
- | Even if it's receiving a ''' | + | Even if it's receiving a '' |
+ | The '' | ||
+ | |||
+ | For this reason adding a type to '' | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to allow ''' | + | This RFC proposes to allow '' |
+ | The rest of the current behavior of '' | ||
+ | |||
+ | A '' | ||
+ | |||
+ | <code php> | ||
+ | class Foo{ | ||
+ | function method1 (): void {} | ||
+ | function method2 () {} | ||
+ | } | ||
+ | |||
+ | class Bar extends Foo{ | ||
+ | function method1 (): array { return []; } | ||
+ | function method2 (): array { return []; } | ||
+ | } | ||
+ | |||
+ | class Baz extends Foo{ | ||
+ | function method1 () { return 42; } | ||
+ | function method2 () { return 42; } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Except that '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code php> | ||
+ | class Foo{ | ||
+ | function method (): void {} | ||
+ | } | ||
+ | |||
+ | class Bar extends Foo{ | ||
+ | function method () {} // ok | ||
+ | } | ||
+ | |||
+ | class Baz extends Bar{ | ||
+ | function method (): void {} // error: can't go back to void | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This is technically not invalid since '' | ||
+ | |||
+ | And, more obviously, also the following is disallowed: | ||
+ | |||
+ | <code php> | ||
+ | class Foo{ | ||
+ | function method (): void {} | ||
+ | } | ||
+ | |||
+ | class Bar extends Foo{ | ||
+ | function method (): string {} // ok | ||
+ | } | ||
+ | |||
+ | class Baz extends Bar{ | ||
+ | function method (): void {} // error: can't go back to void | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Precedents in other languages ===== | ||
+ | |||
+ | TypeScript does this (are there other languages? | ||
+ | |||
+ | ===== Backward Incompatible Changes ===== | ||
+ | |||
+ | None. | ||
+ | |||
+ | ===== Proposed PHP Versions ===== | ||
+ | 7.2.x, 7.3.x, 7.4.x | ||
+ | ===== Voting ===== | ||
+ | 2/3 majority will be required. | ||
+ | ===== References ===== | ||
+ | https:// | ||
rfc/allow-void-variance.txt · Last modified: 2019/02/04 07:48 by wesnetmo