Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57052 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12449 invoked from network); 23 Dec 2011 01:48:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2011 01:48:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qw0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:56200] helo=mail-qw0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 31/53-28504-5DDD3FE4 for ; Thu, 22 Dec 2011 20:48:06 -0500 Received: by qadc14 with SMTP id c14so6114297qad.8 for ; Thu, 22 Dec 2011 17:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=adBHpJipcMvhBTU/yfvS5yTZbcbQ5O2bjwnNmV1ChgQ=; b=qne8ibqo9PW6NwEMa1sCwgOBhr4YWspRxVMh22D+egwUTyLmE99en0dA6aOqsRIxqo xMdOHB/hAlfUftvMPQOqEYpBW5TfDmcqowoudbttMWrXaiyhJ39bOq7jgB6GyR+aJxZ/ yebElRpqqvfU4kVJnG4/YxZRTYF1zmnw+nMCk= Received: by 10.224.192.3 with SMTP id do3mr16358615qab.58.1324604882218; Thu, 22 Dec 2011 17:48:02 -0800 (PST) Received: from [10.0.0.10] (c-71-225-170-108.hsd1.pa.comcast.net. [71.225.170.108]) by mx.google.com with ESMTPS id j7sm20862702qaq.11.2011.12.22.17.48.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Dec 2011 17:48:00 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=iso-8859-1 In-Reply-To: <4EF3C99F.4010300@gmail.com> Date: Thu, 22 Dec 2011 20:47:58 -0500 Cc: PHP Developers Mailing List Content-Transfer-Encoding: quoted-printable Message-ID: <3D5E9FD9-74DF-4CF5-B46A-E90ED4E0A152@gmail.com> References: <2095305E-D4E3-4D7E-8218-32EE99688E0C@GMAIL.COM> <2C90FB94-38C4-4270-8C6A-B89304BA8ED8@gmail.com> <159A7CA2-8561-40DA-9434-CAAE12304DDB@gmail.com> <4EF3B56A.4040809@gmail.com> <-2451498990672032588@unknownmsgid> <4EF3C99F.4010300@gmail.com> To: =?iso-8859-1?Q?=C1ngel_Gonz=E1lez?= X-Mailer: Apple Mail (2.1251.1) Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: will.fitch@gmail.com (Will Fitch) On Dec 22, 2011, at 7:21 PM, =C1ngel Gonz=E1lez wrote: > On 23/12/11 00:08, Will Fitch wrote: >> Sent from my iPad >> On Dec 22, 2011, at 5:51 PM, "=C1ngel Gonz=E1lez" = wrote: >>=20 >>> Your examples only show class methods with visibility qualifyiers, = and >>> looking at the changes to zend_language_parser.y >>> it seems as if would only be available for methods. Wouldn't return >>> hints be available for plain functions? >> Right now, it's only available for methods. Personally, I'm not a fan >> of return types for functions. Adding this for functions in its form >> today will also introduce shift/reduce issues. > Yes, it's much easier for the parser for methods with explicit > visibility (note that public is optional). > I'm ok on requiring the public for methods with a return hint, but if > methods can get return hints, > normal functions must, too. >=20 > If it's hard with your proposed syntax, it should be discarded and a > better one developed. > Else we would end up with different syntaxes for return hints = depending > on the kind of function. It's not a matter of being difficult. I can see your argument, however. >=20 >=20 > For instance, the return hint could go at the end of the prototype: >=20 > function foo (Class1 $a, Class2 $b) =3D> Class3 { > return new Class3($a, $b); > } >=20 > (I'm unsure about the T_DOUBLE_ARROW, although for parsing, I feel = there > should be some token there > before the class name, though I'm unconvinced on which) Let me see what can be done without doing too much to the definitions. = I like the idea of not making "function" required. >=20 >=20 >>> In functional programming, it is common to return nullable types: >>> returns an instance of class Foo or null, an array or false, etc. >>>=20 >>> This is supported in normal arguments with the "=3D null" hint, and = I >>> think there should be something equivalent for return types. >>> Does the proposed implementation allow null everywhere? (there's an >>> example of returning null from a return hint of array) >>> That seems wrong to me. Unless there's a way to make it strict (eg. >>> array! for only arrays). >> Most modern languages allow returning null in any case. This is a = hail >> Mary in the event something happens, but throwing an exception is >> inappropriate. I see no reason to diverge from that. > I disagree with you, but Stas already provided a compelling case. >=20