rfc:covariant-returns-and-contravariant-parameters

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
rfc:covariant-returns-and-contravariant-parameters [2018/11/26 21:57]
levim Fix link formatting.
rfc:covariant-returns-and-contravariant-parameters [2019/01/16 18:18]
levim RFC is accepted.
Line 3: Line 3:
   * Date: 2018-09-20   * Date: 2018-09-20
   * Author: Levi Morrison <​levim@php.net>​   * Author: Levi Morrison <​levim@php.net>​
-  * Status: ​Under Discussion+  * Status: ​Accepted
   * First Published at: http://​wiki.php.net/​rfc/​covariant-returns-and-contravariant-parameters   * First Published at: http://​wiki.php.net/​rfc/​covariant-returns-and-contravariant-parameters
  
Line 37: Line 37:
  
 This RFC does not add variance support to the ''​callable''​ type. Anyone desiring improved ''​callable''​ type support should create a different RFC. This RFC does not add variance support to the ''​callable''​ type. Anyone desiring improved ''​callable''​ type support should create a different RFC.
 +
 +This RFC also expands support for compile-time resolving of the "​parent"​ pseudo-type. The existing engine does this in some places, but not extensively. This work is included in the RFC because it made the code for the RFC a bit easier, but if necessary this work can be split out.
  
 ==== Examples ==== ==== Examples ====
Line 113: Line 115:
 ==== Pass By Reference / Return By Reference ==== ==== Pass By Reference / Return By Reference ====
  
-Whether a parameter is passed by-reference or not does not impact the variance. This is because the type checks are moment-in-time checks, not lifetime checks. ​Thereforeby-reference parameters are still contravariant,​ and by-reference returns are still covariant.+Whether a parameter is passed by-reference or not does not impact the variance. This is because the type checks are moment-in-time checks, not lifetime checks. ​For examplethis is valid:
  
-It is possible that in the future we may get ''​out''​ or ''​inout''​ parameter types, which behave more like references to typed properties. These would be required to be invariant.+<​PHP>​function array_baz(array &$in) { 
 +  $in = 1; 
 +
 +$array = []; 
 +array_baz($array);​ // valid 
 +var_export($array);​ // 1</​PHP>​ 
 + 
 +Therefore, by-reference parameters are still contravariant,​ and by-reference returns are still covariant. ​It is possible that in the future we may get ''​out''​ or ''​inout''​ parameter types, which behave more like references to typed properties. These would probably have different variance requirements.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
 There are no intended incompatibilities. All incompatibilities should be reported and treated as bugs. There are no intended incompatibilities. All incompatibilities should be reported and treated as bugs.
 +
 +This patch does emit a new ''​E_DEPRECATED''​ warning when the "​parent"​ pseudo-type is used in places that do not have a parent type. In the next major version (currently 8.0) this should elevated to an ''​E_COMPILE_ERROR''​. Emitting new warnings are generally not considered backwards incompatible changes even though they technically can break things with custom error handlers. Again, this work with compile-time resolving of "​parent"​ can be split out from the RFC if necessary.
  
 ===== RFC Impact To Existing Extensions ==== ===== RFC Impact To Existing Extensions ====
Line 129: Line 140:
 This RFC requires two-thirds of voters to select "​yes"​ for this RFC to pass. This RFC requires two-thirds of voters to select "​yes"​ for this RFC to pass.
  
-<doodle title="​Accept Covariant Returns and Contravariant Parameters?"​ auth="levim" voteType="​single"​ closed="​true">​+Voting will be open until at least January 2nd, 2019 (2019-01-02). 
 + 
 +<doodle title="​Accept Covariant Returns and Contravariant Parameters?"​ auth="user" voteType="​single"​ closed="​true">​
    * Yes    * Yes
    * No    * No
Line 156: Line 169:
  
 ===== References ===== ===== References =====
-Announcement to Internals mailinglist ​[[https://​marc.info/?​l=php-internals&​m=154326760510934&​w=2|@marc.info]] [[https://​externals.io/​message/​103511|@externals.io]].+Announcement to Internals mailinglist:​
  
 +  * [[https://​marc.info/?​l=php-internals&​m=154326760510934&​w=2|marc.info]]
 +  * [[https://​externals.io/​message/​103511|externals.io]]
 +  * [[http://​news.php.net/​php.internals/​103511|news.php.net]]
rfc/covariant-returns-and-contravariant-parameters.txt · Last modified: 2019/06/13 16:38 by nikic