rfc:return_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:return_types [2015/01/14 00:36] – levim | rfc:return_types [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Date: 2014-03-20 | * Date: 2014-03-20 | ||
* Author: Levi Morrison < | * Author: Levi Morrison < | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
* Migrated to: https:// | * Migrated to: https:// | ||
Line 13: | Line 13: | ||
Declaring return types has several motivators and use-cases: | Declaring return types has several motivators and use-cases: | ||
* Prevent sub-types from breaking the expected return type of the super-type((See [[# | * Prevent sub-types from breaking the expected return type of the super-type((See [[# | ||
- | * Prevent unintended return | + | * Prevent unintended return |
* Document return type information in a way that is not easily invalidated (unlike comments) | * Document return type information in a way that is not easily invalidated (unlike comments) | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This proposal adds an optional return type declaration to function declarations including closures, functions, generators, | + | This proposal adds an optional return type declaration to function declarations including closures, functions, generators, |
Here is a brief example of the syntax in action: | Here is a brief example of the syntax in action: | ||
Line 166: | Line 166: | ||
get_config(); | get_config(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 178: | Line 178: | ||
answer(); | answer(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 190: | Line 190: | ||
foo(); | foo(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 210: | Line 210: | ||
} | } | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 227: | Line 227: | ||
This proposal specifically does not allow declaring multiple return types; this is out of the scope of this RFC and would require a separate RFC if desired. | This proposal specifically does not allow declaring multiple return types; this is out of the scope of this RFC and would require a separate RFC if desired. | ||
- | If you want to use multiple return types, simply omit a return type declaration and rely on PHP's excellent dynamic nature. | + | If you want to use multiple return types in the meantime, simply omit a return type declaration and rely on PHP's excellent dynamic nature. |
==== Reflection ==== | ==== Reflection ==== | ||
Line 262: | Line 262: | ||
This RFC modifies the PHP language syntax and therefore requires a two-third majority of votes. | This RFC modifies the PHP language syntax and therefore requires a two-third majority of votes. | ||
- | <del>Should return types as outlined in this RFC be added to the PHP language? Voting will end on November 14th, 2014.</ | + | Should return types as outlined in this RFC be added to the PHP language? Voting will end on January 23, 2015. |
- | A bug was found during the voting period that will require enough changes to how the RFC works that voting has been cancelled. | + | <doodle title=" |
- | <doodle title=" | + | |
* Yes | * Yes | ||
* No | * No | ||
Line 272: | Line 271: | ||
Dmitry and I have updated the implementation to a more current master branch here: https:// | Dmitry and I have updated the implementation to a more current master branch here: https:// | ||
+ | |||
+ | This RFC was merged into the master branch (PHP 7) in commit [[https:// | ||
===== Future Work ===== | ===== Future Work ===== | ||
Ideas for future work which are out of the scope of this RFC include: | Ideas for future work which are out of the scope of this RFC include: | ||
- | * Allowing | + | * Allow functions to declare that they do not return anything at all ('' |
- | * Allowing | + | * Allow nullable types (such as < |
- | * Improving | + | * Improve |
- | * Improving | + | * Improve |
- | * Updating | + | * Update |
===== References ===== | ===== References ===== |
rfc/return_types.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1