rfc:mixed_type_v2
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:mixed_type_v2 [2020/04/20 01:05] – format danack | rfc:mixed_type_v2 [2020/04/20 08:15] – kocsismate | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Mixed Type v2 ====== | ====== PHP RFC: Mixed Type v2 ====== | ||
- | * Version: 0.1 | + | * Version: 0.9 |
* Date: 2020-03-23 | * Date: 2020-03-23 | ||
* Author: Máté Kocsis < | * Author: Máté Kocsis < | ||
- | * Based on previous RFC by: Michael Moravec | + | * Based on previous RFC by: Michael Moravec |
* Target Version: 8.0 | * Target Version: 8.0 | ||
* Status: In Draft | * Status: In Draft | ||
- | * Implementation: | + | * Implementation: |
* First Published at: https:// | * First Published at: https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | With the addition of scalar types in PHP 7, nullables in 7.1, `object` in 7.2, and lastly, union types in 8.0, people writing PHP code can explicitly declare type information for most function parameters, function returns, as well as class properties. | + | With the addition of scalar types in PHP 7, nullables in 7.1, object in 7.2, and lastly, union types in 8.0, people writing PHP code can explicitly declare type information for most function parameters, function returns, as well as class properties. |
However, PHP has not always supported types, and most probably it will always allow to omit type information. But this leads to the problem that its meaning is ambiguous when type information is missing: | However, PHP has not always supported types, and most probably it will always allow to omit type information. But this leads to the problem that its meaning is ambiguous when type information is missing: | ||
- | * the type is a specific type, but the programmer forgot to declare it. | + | |
- | * the type is a specific type, but the programmer omitted it to keep compatibility with an older PHP version | + | * the type is a specific type, but the programmer omitted it to keep compatibility with an older PHP version |
- | * the type is not currently expressible in PHP's type system, and so no type could be specified. | + | * the type is not currently expressible in PHP's type system, and so no type could be specified. |
- | * for return types, it is not clear if the function will or will not return a value, other than null. | + | * for return types, it is not clear if the function will or will not return a value, other than null. |
An explicit '' | An explicit '' | ||
Line 24: | Line 24: | ||
Currently, '' | Currently, '' | ||
- | One prominent example where the '' | + | One prominent example where the '' |
Additionally, | Additionally, | ||
Line 40: | Line 40: | ||
==== LSP, Covariance and Contravariance ==== | ==== LSP, Covariance and Contravariance ==== | ||
- | The proposal conforms to the [Liskov Substituion Priniciple](https:// | + | The proposal conforms to the [[https:// |
- | Since 7.4 PHP allows [covariant returns and contravariant parameters](https:// | + | Since 7.4 PHP allows [[https:// |
PHP allows contravariance (aka type widening) for parameter types to obey the LSP principle. A subclass may use a ' | PHP allows contravariance (aka type widening) for parameter types to obey the LSP principle. A subclass may use a ' | ||
Line 124: | Line 124: | ||
==== Property types are invariant ==== | ==== Property types are invariant ==== | ||
- | Following the [typed properties RFC](https:// | + | Following the [[typed properties RFC|https:// |
<code php> | <code php> | ||
Line 218: | Line 218: | ||
Currently this only affects inheritance in classes. | Currently this only affects inheritance in classes. | ||
- | If/when PHP gains the abilties to declare [function signatures as types](https:// | + | If/when PHP gains the abilties to declare [[https:// |
==== Signature checking of function when no return type present ==== | ==== Signature checking of function when no return type present ==== | ||
Line 284: | Line 284: | ||
This RFC proposes '' | This RFC proposes '' | ||
- | Also, choosing to use '' | + | Also, choosing to use '' |
Line 295: | Line 295: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Since PHP 7.0, '' | + | Since PHP 7.0, '' |
===== To SAPIs ===== | ===== To SAPIs ===== |
rfc/mixed_type_v2.txt · Last modified: 2020/05/22 14:22 by kocsismate