rfc:never_for_parameter_types

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:never_for_parameter_types [2021/08/14 17:33] – Removed explicit widening jordanrlrfc:never_for_parameter_types [2021/08/24 11:53] (current) – Withdrawing jordanrl
Line 3: Line 3:
   * Date: 2021-08-14   * Date: 2021-08-14
   * Author: Jordan LeDoux, jordan.ledoux@gmail.com   * Author: Jordan LeDoux, jordan.ledoux@gmail.com
-  * Status: In Discussion+  * Status: Withdrawn
   * First Published at: http://wiki.php.net/rfc/never_for_parameter_types   * First Published at: http://wiki.php.net/rfc/never_for_parameter_types
  
 ===== 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>
Line 27: Line 27:
 </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 =====
Line 91: Line 91:
 Allow the use of ''never'' as a type for arguments in interfaces and classes. This would have the following semantics: Allow the use of ''never'' as a type for arguments in interfaces and classes. This would have the following semantics:
  
-  * ''never'' cannot be used in an intersection type or union type. Any intersection would reduce to ''never'', and any union would reduce `neverout of the union, as ''never'' is the identity type of unions.+  * ''never'' cannot be used in an intersection type or union type. Any intersection would reduce to ''never'', and any union would reduce ''never'' out of the union, as ''never'' is the identity type of unions.
   * Attempting to call code directly that uses the ''never'' type for an argument would result in a ''TypeError'', as no zval will match this type.   * Attempting to call code directly that uses the ''never'' type for an argument would result in a ''TypeError'', as no zval will match this type.
  
Line 100: Line 100:
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-This change is proposed for next PHP 8.x+This change is proposed for PHP 8.2
  
 ===== RFC Impact ===== ===== RFC Impact =====
Line 138: Line 138:
  
 ===== 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
   * https://blog.logrocket.com/when-to-use-never-and-unknown-in-typescript-5e4d6c5799ad/   * https://blog.logrocket.com/when-to-use-never-and-unknown-in-typescript-5e4d6c5799ad/
 +  * https://externals.io/message/115712
  
 ===== Changelog ===== ===== Changelog =====
rfc/never_for_parameter_types.1628962396.txt.gz · Last modified: 2021/08/14 17:33 by jordanrl