rfc:nullable_return_types

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:nullable_return_types [2016/04/06 15:53] – created dmitryrfc:nullable_return_types [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2016-04-06   * Date: 2016-04-06
   * Author: Dmitry Stogov, dmitry@zend.com   * Author: Dmitry Stogov, dmitry@zend.com
-  * Status: Under Discussion+  * Status: Draft
   * First Published at: https://wiki.php.net/rfc/nullable_return_types   * First Published at: https://wiki.php.net/rfc/nullable_return_types
  
Line 58: Line 58:
 </code> </code>
  
-Usage of the same **?<type>** syntax for arguments (and later properties) is not the subject of this RFC+==== Nullable Arguments without Default Values ==== 
-Actually, arguments already may be declared as "nullable" using NULL default value (the same may be done for properties). + 
-This decision(s) may be done separately.+Usage of the same **?<type>** syntax for arguments (and later properties) is not the primary goal of this RFC, because arguments already may be declared as "nullable"using NULL default value (the same may be done for properties). It's also possible to add the same syntax for arguments as it was proposed in [[https://wiki.php.net/rfc/nullable_types|"Declaring Nullable Types" RFC]] 
 + 
 +<code> 
 +function foo(int $a = null{ // already works in 7.0 
 +
 + 
 +function foo(?int $a) { // we may make this work as well 
 +
 +</code> 
 + 
 +==== Inherited Method Compatibility Rules ==== 
 + 
 +Nullable types won't change anything in inherited method compatibility rules. We will still use Covariance for return types and Contravariance for arguments. This means, that methods with nullable return types may be overridden by methods with non-nullable, but methods with non-nullable return types can't be overridden by methods with nullable.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 72: Line 84:
  
 ===== Future Scope ===== ===== Future Scope =====
- 
-==== Nullable Arguemnts without Default Values ==== 
- 
-This RFC doesn't propose any change to argument (or property) type declarations. The following code won't work, but this RFC doesn't prohibit to support this syntax later. 
- 
-<code> 
-function foo(?int $a) { 
-} 
-</code> 
  
 ==== Union Types ==== ==== Union Types ====
Line 91: Line 94:
 </code> </code>
  
-===== Proposed Voting Choices ===== +I don't see a big reason to extend PHP with both possible syntaxes, so this RFC competes with "Union Typesand only one should be selected. The implementation of this RFC is very simple and efficient. "Union Types" RFC, on the other hand, will have to make decision about support for multiple class names in a single declaration and this decision may lead to inconsistency or expensive implementation (then we will have to keep many class names, and then in run-time perform multiple class lookups and checks).
-Simple "Yes/Nowith 2/3 majority to be accepted.+
  
 +===== Proposed Voting Choices =====
 The vote will start on April 25 and finish on May 9. The vote will start on April 25 and finish on May 9.
 +
 +<doodle title="Enable nullable return types (2/3 majority requited):" auth="dmitry" voteType="single" closed="true">
 +   * yes
 +   * no
 +</doodle>
 +
 +<doodle title="In addition enable nullable argument without default value (1/2 majority required):" auth="dmitry" voteType="single" closed="true">
 +   * yes
 +   * no
 +</doodle>
 +
 +
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 110: Line 125:
   - [[https://docs.hhvm.com/hack/types/type-system#nullable|Nullable Types in HHVM]]   - [[https://docs.hhvm.com/hack/types/type-system#nullable|Nullable Types in HHVM]]
   - [[https://wiki.php.net/rfc/typed-properties|"Typed Properties" RFC]]   - [[https://wiki.php.net/rfc/typed-properties|"Typed Properties" RFC]]
 +  - [[https://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29|Covariance and contravariance]]
  
rfc/nullable_return_types.1459958039.txt.gz · Last modified: 2017/09/22 13:28 (external edit)