rfc:return_types
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:return_types [2015/01/14 00:12] – Migrated to new url levim | rfc:return_types [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Return Type Declarations ====== | ====== PHP RFC: Return Type Declarations ====== | ||
- | * Version: | + | * Version: |
* 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:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 12: | 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 102: | Line 103: | ||
- Allowing '' | - Allowing '' | ||
- | The [[rfc:nullable_typehints|Nullable Types RFC]] addresses this shortcoming and more. | + | The [[rfc:nullable_types|Nullable Types RFC]] addresses this shortcoming and more. |
==== Methods which cannot declare return types ==== | ==== Methods which cannot declare return types ==== | ||
Line 165: | Line 166: | ||
get_config(); | get_config(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 177: | Line 178: | ||
answer(); | answer(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 189: | Line 190: | ||
foo(); | foo(); | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 209: | Line 210: | ||
} | } | ||
</ | </ | ||
- | '' | + | '' |
---- | ---- | ||
Line 226: | 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 261: | 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 271: | 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 ===== | ||
Line 295: | Line 297: | ||
===== Changelog ===== | ===== Changelog ===== | ||
- | * v1.1: RFC now targets | + | * v1.1: Target |
* v1.2: Disallow return types for constructors, | * v1.2: Disallow return types for constructors, | ||
- | * v1.3: Reworked | + | * v1.3: Rework |
- | * v1.3.1: | + | * v1.3.1: |
- | * v1.4: Change to invariant return types and omit reflection support | + | * v2.0: Change to invariant return types and omit reflection support |
rfc/return_types.1421194375.txt.gz · Last modified: 2017/09/22 13:28 (external edit)