Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88803 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56833 invoked from network); 15 Oct 2015 01:16:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2015 01:16:38 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.27 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.27 out3-smtp.messagingengine.com Received: from [66.111.4.27] ([66.111.4.27:42386] helo=out3-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/98-33697-57EFE165 for ; Wed, 14 Oct 2015 21:16:38 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C63D720824 for ; Wed, 14 Oct 2015 21:16:35 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 14 Oct 2015 21:16:35 -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=nuGLojdvqoaRhDi sxDIdQpD7ArA=; b=RL6qs64kMz+fiEV8D1K/YVD8QNtguQMQURmaa7iarAUka9/ A9lZNV7WBYP+/GgPVwCKaAwR0glAb1SKtMUXVzyoSTf45Z5MGipxhbppQW5hlvuh vEkXsANa96g5FcJWanCSs+2NT879bGtwEYwPJu0OagXlJ+IyS0MPbP/CG3ds= X-Sasl-enc: c3rKjCuGvwQbDG1c67DwdHhzvAyL8q8DWiO06pdzmoMr 1444871795 Received: from [192.168.42.5] (c-73-208-148-59.hsd1.il.comcast.net [73.208.148.59]) by mail.messagingengine.com (Postfix) with ESMTPA id 880F06800A3 for ; Wed, 14 Oct 2015 21:16:35 -0400 (EDT) To: internals@lists.php.net References: <0A.C2.33697.6AECE165@pb1.pair.com> <561ED07E.4060809@gmail.com> <561EE2F1.7050305@garfieldtech.com> <26.08.33697.F95EE165@pb1.pair.com> Message-ID: <561EFE73.3060602@garfieldtech.com> Date: Wed, 14 Oct 2015 20:16:35 -0500 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: <26.08.33697.F95EE165@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: =?UTF-8?Q?Re:_[PHP-DEV]_[RFC]_Void_Return_Type_=28v0.2=2c_re=c3=b6p?= =?UTF-8?Q?ening=29?= From: larry@garfieldtech.com (Larry Garfield) On 10/14/2015 06:30 PM, Andrea Faulds wrote: > Which I believe gives the following options: >> >> 1) Change the language behavior such that >> >> function foo() : void { ...} >> $a = foo(); >> >> Is a syntax error (because there really was nothing returned to assign), >> rather than resulting in $a having a value of NULL. > > As the RFC notes, this breaks things, and is inconsistent with how PHP > already does things. > >> 2) Use null as a "type" (which I agree feels weird just saying it), such >> that: >> >> function foo() : null { ...} >> $a = foo(); >> >> and >> >> function foo() { ...} >> $a = foo(); >> >> are identical. The former would impact the contents of the function >> (eg, a non-empty return would be a parse error), but the external result >> is the same ($a == NULL). > > This would be strange. The manual doesn't say `null`, and I can't > think of any language which uses `null` as the return type in this > situation, even when they have the same implicit-null-return behaviour > that PHP has (see the email you're replying to). > > Also, wouldn't you expect this to behave like existing type hints, and > let you return a null value from any source? But that's not what you > would actually want, right? > > Thanks. Well, that depends on the intent here. In practice, is the intent to add a "no return at all" type of function (ie, $a = foo() is a syntax error now where it was not before), or to make it explicit that the only legal return is null (even if implicitly that means having a non-early return statement is pointless)? Those are the two options. That may or may not dictate the keyword that gets used. It definitely sounds like you're favoring the second (as that's what the RFC says). Which may or make not make "void" an odd keyword to choose when what's actually happening is NULL getting returned. Is NULL a void? (There's a deep philosophical question...) As I said, I don't have a strong opinion on the subject yet. I'm just trying to distil the discussion down to as small a question as possible. :-) Cheers. --Larry Garfield