AW: [PHP-DEV] Re: [RFC] Void Return Type (v0.2 , reöpening)
| From: | Robert Stoll | Date: | Fri, 16 Oct 2015 09:04:07 +0000 |
| Subject: | AW: [PHP-DEV] Re: [RFC] Void Return Type (v0.2 , reöpening) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88850@lists.php.net to get a copy of this message | ||
Hi Andrea
> -----Ursprüngliche Nachricht-----
> Von: Andrea Faulds [mailto:ajf@ajf.me]
> Gesendet: Donnerstag, 15. Oktober 2015 23:04
> An: internals@lists.php.net
> Betreff: [PHP-DEV] Re: [RFC] Void Return Type (v0.2, reöpening)
>
> Hi everyone,
>
> Andrea Faulds wrote:
> > I'm reviving my Void Return Type RFC, this time for PHP 7.1:
> >
> > https://wiki.php.net/rfc/void_return_type
> >
> > Please read it and tell me your thoughts!
>
> Since the void/null naming issue has been a frequently-asked question, I've added a
> subsection to the RFC explaining
why I
> chose this name. It doesn't really say anything I haven't said already, it just
> summarises it. In particular, it lists
a bunch of
> languages using
void, some of which do what PHP does.
>
> The new section is here:
>
> https://wiki.php.net/rfc/void_return_type#why_call_it_void_and_not_null
>
> Thanks.
>
> --
> Andrea Faulds
> http://ajf.me/
>
> --
> PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:
> http://www.php.net/unsub.php
You write in your RFC "others do allow void functions in expressions, just as PHP does, by
making them implicitly return
some unit type."
You mentioned TypeScript -- unit type = null -- ActionScript -- unit type = undefined -- and Swift
-- unit type = empty
tuple, ergo ().
TypeScript [1] allows to return null, ActionScript does not allow to return undefined, and Swift
allows to return an
empty tuple explicitly [2].
I agree with others that is seems inconsistent to use the name void but allow to use void functions
in expression
(return implicitly a unit type) and in the same time forbid to return the unit type explicitly in
such functions.
IMO ActionScript should have allowed to return the unit type explicitly as well and so should PHP.
At first I did not like the idea of introducing void in PHP at all if it has not the same behaviour
as in C -- meaning
it should be forbidden to use void functions in expressions -- but now I think it better suits PHP
if void stands for
return nothing (hence null implicitly) or null explicitly. I think you should change your RFC to
allow returning
explicitly null for two reasons:
1. Implicit and explicit behaviour should be consistent. If a function returns null implicitly then
it should be allowed
to return null explicitly.
2. Not everyone might be aware of the implicit behaviour and some code conventions might want to be
explicit on this
part and dictate that one needs to express the behaviour in code.
To conclude, personally I want that the following are all equivalent:
function foo() : void {}
function foo() : void { return; }
function foo() : void { return null; }
To go a step further, I kind of like the idea that using the return value of a void function results
(at least) in an
E_NOTICE. But maybe that is something for PHP 8.
Another random thought, why not treat void like Void [3] in Java where null is the only valid value
of this type? Nah...
bad idea, would be too heavy to use an object everywhere and secondly it would force to write
"return null;" all the
time, so forget about it.
[1] http://www.typescriptlang.org/Playground#src=function%20foo()%3Avoid%7Breturn%20null%3B%7D%0A
[2] http://swiftstub.com/114266460/?v=gm
[3] http://docs.oracle.com/javase/7/docs/api/java/lang/Void.html