rfc:mixed_type_v2

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
rfc:mixed_type_v2 [2020/04/20 01:12]
danack Formatting links.
rfc:mixed_type_v2 [2020/05/22 14:22] (current)
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 <kocsismate@php.net>, Danack<danack@php.net>   * Author: Máté Kocsis <kocsismate@php.net>, Danack<danack@php.net>
   * Based on previous RFC by: Michael Moravec   * Based on previous RFC by: Michael Moravec
-  * Target Version: 8.0 +  * Status: Implemented 
-  * Status: In Draft +  * Implementation: https://github.com/php/php-src/pull/5313
-  * Implementation:+
   * First Published at: https://wiki.php.net/rfc/mixed_type_v2   * First Published at: https://wiki.php.net/rfc/mixed_type_v2
  
 ===== Introduction ===== ===== Introduction =====
  
-With the addition of scalar types in PHP 7, nullables in 7.1, `objectin 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:
Line 272: Line 271:
 //INVALID - Fatal error: Mixed types cannot be nullable, null is already part of the mixed type. //INVALID - Fatal error: Mixed types cannot be nullable, null is already part of the mixed type.
 function bar(): ?mixed {} function bar(): ?mixed {}
 +</code>
 +
 +
 +
 +==== Explicit returns ==== 
 +
 +When using mixed as a return type, a value must be explicitly returned from the function, otherwise a TypeError will be thrown.
 +
 +<code php>
 +function foo(): mixed {}
 +
 +foo();
 +
 +// Uncaught TypeError: Return value of foo() must be of 
 +// the type mixed, none returned
 +</code>
 +
 +This is consistent with the existing behaviour for other return types.
 +
 +<code php>
 +function bar(): ?int {}
 +bar();
 +// Uncaught TypeError: Return value of bar() must be of 
 +// the type int or null, none returned
 +
 </code> </code>
  
Line 295: Line 319:
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-Since PHP 7.0, ''mixed'' is a 'soft' reserved word.+Since PHP 7.0, ''mixed'' is a 'soft' reserved word. This RFC would prevent the use of ''mixed'' as a class name if it is passed.
  
 ===== To SAPIs ===== ===== To SAPIs =====
Line 306: Line 330:
 Not analyzed. Not analyzed.
  
-===== Proposed Voting Choices ===== +===== Vote =====  
 +The vote starts on 2020-05-07 and ends on 2020-05-21 12:00 UTC. The vote requires 2/3 majority to be accepted.
  
-Add ''mixed'' as a type to be used as parameter, return and class property types - yes/no.+<doodle title="Add mixed as a type to be used as parameter, return and class property types?" auth="kocsismate" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
  
rfc/mixed_type_v2.1587345124.txt.gz · Last modified: 2020/04/20 01:12 by danack