rfc:parameter-no-type-variance
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:parameter-no-type-variance [2016/11/21 09:32] – Draft → Under Discussion kelunik | rfc:parameter-no-type-variance [2017/01/31 07:07] – fix voting sentence kelunik | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: Parameter Type Widening |
- | * Version: 0.1.1 | + | * Version: 0.3 |
- | * Date: 2016-11-21 | + | * Date: 2017-01-03 |
- | * Author: Niklas Keller < | + | * Authors: Niklas Keller < |
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
- | |||
- | ===== Introduction ===== | ||
- | PHP doesn' | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to allow ommiting the type entirely in a subclass, as dropping all parameter constraints is always valid according to the LSP principle. | + | PHP currently doesn' |
+ | |||
+ | This RFC proposes to allow omitting a type entirely in a subclass, as dropping all parameter constraints is always valid according to the contravariance rule. | ||
+ | |||
+ | Implementing this RFC would allow libraries to be upgraded to use type declarations in their method signatures. Currently adding types to a method of a class in a library would break any code that extends that class. | ||
+ | |||
+ | This would provide an easier upgrade path for libraries to start using scalar types, to replace manual checks being done inside the methods, without requiring an update for all sub-classes. | ||
+ | |||
+ | Another example of this being useful is '' | ||
+ | |||
+ | A change was made to the '' | ||
==== Example ==== | ==== Example ==== | ||
Line 21: | Line 29: | ||
} | } | ||
- | class IterableClass extends ArrayClass { | ||
- | // This implementation also accepts Traversable. | ||
- | // Variance is already possible in this special case using " | ||
- | public function foo(iterable $foo) { /* ... */ } | ||
- | } | ||
+ | // This RFC proposes allowing the type to be widened to be untyped aka any | ||
+ | // type can be passed as the parameter. | ||
+ | // Any type restrictions can be done via user code in the method body. | ||
class EverythingClass extends ArrayClass { | class EverythingClass extends ArrayClass { | ||
- | // This implementation accepts all values. | ||
- | // Restrictions may be done via user code in the method body. | ||
- | // Variance is currently not allowed, it throws a warning if parent or child miss a type. | ||
public function foo($foo) { /* ... */ } | public function foo($foo) { /* ... */ } | ||
} | } | ||
Line 47: | Line 50: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | Next minor version, currently 7.2. | + | Next version, currently 7.2. |
- | + | ||
- | ===== RFC Impact ===== | + | |
- | ==== To SAPIs ==== | + | |
- | None. | + | |
- | + | ||
- | ==== To Existing Extensions ==== | + | |
- | None. | + | |
- | + | ||
- | ==== To Opcache ==== | + | |
- | None. | + | |
- | + | ||
- | ==== New Constants ==== | + | |
- | None. | + | |
- | + | ||
- | ==== php.ini Defaults ==== | + | |
- | None. | + | |
- | + | ||
- | ===== Open Issues ===== | + | |
- | None. | + | |
===== Future Scope ===== | ===== Future Scope ===== | ||
- | In the future there might be support for contra-variance / co-variance for parameters / return types. | + | Unfortunately " |
- | ===== Proposed | + | ===== Voting ===== |
Requires a 2/3 majority. | Requires a 2/3 majority. | ||
- | ===== Patches and Tests ===== | + | <doodle title=" |
- | TBD. | + | * Yes |
+ | * No | ||
+ | </ | ||
- | ===== Implementation ===== | + | Voting started on 9th of January but has been stopped due to the mailing list failures. Voting has been resumed on 11th of January and has ended on 31th of January. |
- | TBD. | + | |
- | ===== References | + | ===== Patches and Tests ===== |
- | None. | + | |
- | ===== Rejected Features ===== | + | * https:// |
- | None. | + |
rfc/parameter-no-type-variance.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1