rfc:allow-void-variance
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:allow-void-variance [2019/02/04 03:11] – wesnetmo | rfc:allow-void-variance [2019/02/04 07:48] (current) – wesnetmo | ||
---|---|---|---|
Line 6: | Line 6: | ||
* First Published at: http:// | * First Published at: http:// | ||
- | ===== Rationale | + | ===== Introduction |
- | This RFC proposes to change '' | + | This RFC proposes to change |
+ | |||
+ | ===== Rationale ===== | ||
- | The intent of '' | + | **The intent of '' |
It shouldn' | It shouldn' | ||
Line 33: | Line 35: | ||
function myFooConsumer (Foo $foo) { | function myFooConsumer (Foo $foo) { | ||
- | // method() is void, therefore we won't be using its return | + | // method() is void, therefore we won't be using its return |
| | ||
Line 46: | Line 48: | ||
The '' | The '' | ||
- | For this reason adding a type to subclasses is not an invalid operation, and denying it is a pointless restriction. | + | 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 '' | The rest of the current behavior of '' | ||
Line 90: | Line 92: | ||
</ | </ | ||
- | This is not technically invalid since '' | + | This is technically |
+ | |||
+ | 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 ===== | ===== Backward Incompatible Changes ===== | ||
Line 103: | Line 125: | ||
===== References ===== | ===== References ===== | ||
+ | |||
+ | https:// | ||
rfc/allow-void-variance.1549249872.txt.gz · Last modified: 2019/02/04 03:11 by wesnetmo