Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88927 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22360 invoked from network); 23 Oct 2015 22:35:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2015 22:35:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.29 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.29 out5-smtp.messagingengine.com Received: from [66.111.4.29] ([66.111.4.29:34997] helo=out5-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/D1-31172-C36BA265 for ; Fri, 23 Oct 2015 18:35:41 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 084E320204 for ; Fri, 23 Oct 2015 18:35:38 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Fri, 23 Oct 2015 18:35:38 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=Go4RvC3LQFTDq/k sN/fNAehw4rs=; b=KqhfLnKMha+fdzzN1UFk5nFHMcuFwD96aAPYcTQswcLQGqS 8K46aS6niYezatPok6yssXCMHAfdkBOh7vxCPz4Hm2bVBBh3sK96zVeaq2ZE/5/a xq4ocSzpFkorUPnf3a6YTICZKEwsJQqIJUMo9IDIGxXHZLPN06zE3fnji74o= X-Sasl-enc: M97lv0kP9DvXpmo7izhVUEnofloCWLmDI+JGMzognaPT 1445639737 Received: from [172.26.32.114] (unknown [104.129.198.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 8CEB86800B8 for ; Fri, 23 Oct 2015 18:35:37 -0400 (EDT) To: internals@lists.php.net References: <0A.C2.33697.6AECE165@pb1.pair.com> <11.10.09496.8F410265@pb1.pair.com> <001b01d107f1$9d672370$d8356a50$@tutteli.ch> <004101d10844$55f89d90$01e9d8b0$@tutteli.ch> Message-ID: <562AB638.1090304@garfieldtech.com> Date: Fri, 23 Oct 2015 15:35:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <004101d10844$55f89d90$01e9d8b0$@tutteli.ch> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: =?UTF-8?Q?Re:_AW:_[PHP-DEV]_Re:_[RFC]_Void_Return_Type_=28v0.2=2c_r?= =?UTF-8?Q?e=c3=b6pening=29?= From: larry@garfieldtech.com (Larry Garfield) On 10/16/2015 11:56 AM, Robert Stoll wrote: >>> 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 >>> >>> 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 > I agree only to a certain degree. If you had not used the type hint callable, then I could argue that the same applies for passing null to partialLeft. > Hence, the problem is rather that PHP does not yet support callable type hints with return type, something like callable:int, in which case it would be clear that the error was done by the caller. That wouldn't help either, I think. Then you'd need a separate partialLeft(callable:int $cb), partialLeft(callable:string $cb), partialLeft(callable:float $cb), and partialLeft(callable:void $db). And likely others. That seems exactly like what Anthony wants to avoid (rightly). Indirect calls to arbitrary functions does mean that they need to be able to behave consistently when referred to abstractly. Vis, any approach that involves: function foo() : void {} $a = foo(); triggering an error condition would make life drastically more difficult for higher order function operations like partials or memoization. That seems doubleplusungood. One way around that would be to only trigger that behavior on a static call, not a call to a variable function, but I have no idea if that's at all feasible in the engine. I suspect it's more feasible than detecting the function wrapping and only erroring at the top level caller, but now I'm just talking out of my butt. :-) That leaves "documentation of intent for the developer" (which is a valid argument) and "slap someone's hand for returning non-null inside the function itself" (which is valid, but leaves the question of whether return null should error). --Larry Garfield