rfc:mixed_type_v2

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:mixed_type_v2 [2020/04/20 11:20] danackrfc:mixed_type_v2 [2020/04/28 14:44] – added note about explicit returns danack
Line 271: 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>
  
rfc/mixed_type_v2.txt · Last modified: 2020/05/22 14:22 by kocsismate