rfc:never_for_parameter_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
rfc:never_for_parameter_types [2021/08/15 07:41] – formatting fix jordanrl | rfc:never_for_parameter_types [2021/08/17 12:33] – argument -> parameter jordanrl |
---|
| |
===== Introduction ===== | ===== Introduction ===== |
Arguments in PHP are contravariant to preserve Liskov substitution. This means that if class B extends class A, then redefines a function call, the entire type of that argument from class A must be present in the type of the argument in class B: | Parameters in PHP are contravariant to preserve Liskov substitution. This means that if class B extends class A, then redefines a function call, the entire type of that parameter from class A must be present in the type of the parameter in class B: |
| |
<code php> | <code php> |
</code> | </code> |
| |
Thus, the more specific a type is for an argument in a base class, the more broad it can be in an extending class with the requirement that it must also include the type from the base class. | Thus, the more specific a type is for an parameter in a base class, the more broad it can be in an extending class with the requirement that it must also include the type from the base class. |
| |
Since ''never'' is a bottom type within the PHP engine, all other types contain it. This RFC proposes allowing ''never'' as a valid argument type for functions. | Since ''never'' is a bottom type within the PHP engine, all other types contain it. This RFC proposes allowing ''never'' as a valid parameter type for functions. |
| |
===== Use Cases ===== | ===== Use Cases ===== |
| |
===== References ===== | ===== References ===== |
* https://github.com/JordanRL/never-argument-type/edit/master/README.md | * https://github.com/JordanRL/never-argument-type/blob/master/README.md |
* https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) | * https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) |
* https://en.wikipedia.org/wiki/Bottom_type | * https://en.wikipedia.org/wiki/Bottom_type |
rfc/never_for_parameter_types.txt · Last modified: 2021/08/24 11:53 by jordanrl