Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
rfc:void_return_type [2015/10/15 21:03] – Also, -> In addition, so that I don't use 'also' twice in the same sentence ajf | rfc:void_return_type [2015/11/09 00:18] – ends->ended ajf |
---|
====== PHP RFC: Void Return Type ====== | ====== PHP RFC: Void Return Type ====== |
* Version: 0.2.1 | * Version: 0.2.1 |
* Date: 2015-02-14 (v0.1), 2015-10-14 (v0.2, revival) | * Date: 2015-02-14 (v0.1, later withdrawn), 2015-10-14 (v0.2, revival) |
* Author: Andrea Faulds, ajf@ajf.me | * Author: Andrea Faulds, ajf@ajf.me |
* Status: Under Discussion as of 2015-02-14, previously Withdrawn on 2015-02-15 | * Status: Accepted (PHP 7.1) |
* First Published at: http://wiki.php.net/rfc/void_return_type | * First Published at: http://wiki.php.net/rfc/void_return_type |
| |
==== Why call it void and not null? ==== | ==== Why call it void and not null? ==== |
| |
Some have suggested that the return type be named ''null'' instead, since (as previously mentioned) PHP implicitly produces null as the result value for functions which don't explicitly return something, so ''void'' would be almost the same as just enforcing that a function returns null. Plus, ''void'' might suggest a function that can't be used in an expression, whereas ''null'' wouldn't. | Some have suggested that the return type be named ''null'' instead, since (as previously mentioned) PHP implicitly produces null as the result value for functions which don't explicitly return something, so ''void'' would be almost the same as just enforcing that a function returns null. Plus, ''void'' might suggest a function that can't be used in an expression, whereas ''null'' wouldn't. Also, ''void'' would be a new "type" in a sense, whereas ''null'' is preëxisting. |
| |
The main reason to choose ''void'' over ''null'' is that it is the customary name to use for such a return type. We already use ''void'' rather than ''null'' when documenting functions in PHP, both built-in and userland functions: PHP's function prototypes in source code ([[https://github.com/php/php-src/blob/b00a315806ca1ac24b3e1ff97764f9813ad664e6/ext/standard/var.c#L227|e.g.]]), the PHP manual ([[http://php.net/manual/en/function.var-dump.php|e.g.]]) and phpDocumentor's docblock format ([[http://phpdoc.org/docs/latest/guides/types.html#keywords|see definition]]) all use ''void''. In addition, Hack, a PHP-derived and -compatible language which adds its own typing system, [[http://docs.hhvm.com/manual/en/hack.annotations.types.php|also uses void]]. This is just looking at existing PHP practice; most contemporary programming languages use ''void'' here. Some of these ([[https://en.wikipedia.org/wiki/Void_type#In_C_and_C.2B.2B|C, Objective-C and C++]], [[http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-Result|Java]], [[https://msdn.microsoft.com/en-us/library/yah0tteb.aspx|C#]], etc.) prohibit the use of a void function in an expression, but note that others ([[http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf|TypeScript]], [[http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/specialTypes.html#void|ActionScript]], [[https://developer.apple.com/library/watchos/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html|Swift]]) //do// allow void functions in expressions, just as PHP does, by making them implicitly return some unit type. Since ''void'' seems to be the most popular choice for such a return type, both in PHP and elsewhere, why should we name it something different? There's no precedent for it and the name doesn't seem to have been an issue until now. | The main reason to choose ''void'' over ''null'' is that it is the customary name to use for such a return type. We already use ''void'' rather than ''null'' when documenting functions in PHP, both built-in and userland functions: PHP's function prototypes in source code ([[https://github.com/php/php-src/blob/b00a315806ca1ac24b3e1ff97764f9813ad664e6/ext/standard/var.c#L227|e.g.]]), the PHP manual ([[http://php.net/manual/en/function.var-dump.php|e.g.]]) and phpDocumentor's docblock format ([[http://phpdoc.org/docs/latest/guides/types.html#keywords|see definition]]) all use ''void''. In addition, Hack, a PHP-derived and -compatible language which adds its own typing system, [[http://docs.hhvm.com/manual/en/hack.annotations.types.php|also uses void]]. This is just looking at existing PHP practice; most contemporary programming languages use ''void'' here. Some of these ([[https://en.wikipedia.org/wiki/Void_type#In_C_and_C.2B.2B|C, Objective-C and C++]], [[http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-Result|Java]], [[https://msdn.microsoft.com/en-us/library/yah0tteb.aspx|C#]], etc.) prohibit the use of a void function in an expression, but note that others ([[http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf|TypeScript]], [[http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/specialTypes.html#void|ActionScript]], [[https://developer.apple.com/library/watchos/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html|Swift]]) //do// allow void functions in expressions, just as PHP does, by making them implicitly return some unit type. Since ''void'' seems to be the most popular choice for such a return type, both in PHP and elsewhere, why should we name it something different? There's no precedent for it and the name doesn't seem to have been an issue until now. |
This is proposed for the next minor version of PHP, currently PHP 7.1. | This is proposed for the next minor version of PHP, currently PHP 7.1. |
| |
===== Proposed Voting Choices ===== | ===== Vote ===== |
| |
As this is a language change, a 2/3 majority is required. The vote is a straight Yes/No vote for accepting the RFC and merging the patch. | As this is a language change, a 2/3 majority is required. The vote is a straight Yes/No vote for accepting the RFC and merging the patch. |
| |
| Voting started 2015-10-29 and ended <del>10</del> 11 days later on 2015-11-09. |
| |
| <doodle title="Accept the Void Return Type RFC for PHP 7.1 and merge patch into master?" auth="ajf" voteType="single" closed="true"> |
| * Yes |
| * No |
| </doodle> |
| |
===== Patches and Tests ===== | ===== Patches and Tests ===== |