Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88857 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56665 invoked from network); 16 Oct 2015 15:23:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Oct 2015 15:23:13 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.175 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:38363] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6A/66-19126-06611265 for ; Fri, 16 Oct 2015 11:23:13 -0400 Received: by wicll6 with SMTP id ll6so16321449wic.1 for ; Fri, 16 Oct 2015 08:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Xd3pZH7U/1wQtCsnzRHSFkbrybdzqZ4m5jgLrTPO8uo=; b=pwSg0WQh5w/yh0TFoz9ULwmMpzArQjl0RnrUmc2YKzwzz+M7iXKAwOrXLpmgquml6o 0hiOU2o/hYRy8JO8LGXVYKPjAOkK6czYQBq9tv5qbN1yQnx9sppFKaKmWI90fYaCDQyk Sbv4W8Ihv5yCIQwY2cwBouwLhKe+vF1FRSsux1Y7pHhZqMnBL5FzlYLyg3r03fWbuxQ8 RsAy2QUIAs57CvO7Sapb9eQKoTxRn7Pn/rzZm/TsqnyeFs4SX+29JefoNCWwOUk8M1Zq zBbInaAxynGtNEx4h46w7ENsvvrVp+WtIPY9bcVJpLA4bfZ63pCqDTPRPCe+6nyMK4/3 J2Lg== MIME-Version: 1.0 X-Received: by 10.194.201.130 with SMTP id ka2mr17944353wjc.123.1445008989350; Fri, 16 Oct 2015 08:23:09 -0700 (PDT) Received: by 10.28.55.18 with HTTP; Fri, 16 Oct 2015 08:23:09 -0700 (PDT) In-Reply-To: <001b01d107f1$9d672370$d8356a50$@tutteli.ch> References: <0A.C2.33697.6AECE165@pb1.pair.com> <11.10.09496.8F410265@pb1.pair.com> <001b01d107f1$9d672370$d8356a50$@tutteli.ch> Date: Fri, 16 Oct 2015 11:23:09 -0400 Message-ID: To: Robert Stoll Cc: Andrea Faulds , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: =?UTF-8?B?UmU6IFtQSFAtREVWXSBSZTogW1JGQ10gVm9pZCBSZXR1cm4gVHlwZSAodjAuMiwgcmXDtg==?= =?UTF-8?B?cGVuaW5nKQ==?= From: ircmaxell@gmail.com (Anthony Ferrara) Robert, > 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. I dislike this, because it punishes dynamic code (function composition). For example: $logUtility = partialLeft(function(string $a, string $b): void { syslog(LOG_INFO, $a . ": " . $b); }); $log = $log("Prefix"); $log("blah"); // writes "Prefix: blah" to the log function partialLeft(callable $cb) { return function($left) use ($cb) { return function($right) use ($cb, $left) { return $cb($left, $right); }; }; } Boom, notice. Now, we could say that "that's the problem of the caller of partialLeft", but the notice is raised inside of the closure inside of partialLeft. Which would imply that it did something wrong. Something that it couldn't possibly know about without booting a reflectionfunction for it. This would mean that generic higher order functions would need to be duplicated, one for void functions and one for non-void functions. A bit overkill... That's just my $0.02 Anthony