Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57066 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5059 invoked from network); 23 Dec 2011 23:47:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2011 23:47:17 -0000 Authentication-Results: pb1.pair.com header.from=will.fitch@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=will.fitch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:36743] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/53-16446-40315FE4 for ; Fri, 23 Dec 2011 18:47:17 -0500 Received: by eaai11 with SMTP id i11so8966540eaa.29 for ; Fri, 23 Dec 2011 15:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=references:from:in-reply-to:mime-version:date:message-id:subject:to :cc:content-type; bh=UN45oNJMXLWBHqDIHPHjeanpaYY8np2smQyrgs2U+mY=; b=LpQiLejN7rMnfj3ycb4u9S6A8aWz0uhB2XK99Aj58v/mDgofK8v44nQWlIv/QGv8zQ E8DxipSLYivmasrAzSd7Vn6TWn2JavRHCLMI/ky3//vOXGYX1t3Ct8LdtOR85vv9yXO0 ThKx11EA9BVxzYv/8yOMXzzdnNaOu/5054wg8= Received: by 10.205.120.135 with SMTP id fy7mr4793943bkc.54.1324684032962; Fri, 23 Dec 2011 15:47:12 -0800 (PST) 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> <4EF3BD21.2040301@sugarcrm.com> <-6952580475866195972@unknownmsgid> <4EF3C7F7.9010404@sugarcrm.com> <4841689055873111589@unknownmsgid> <4EF3D18B.7040900@sugarcrm.com> <11CFB4E4-F2DA-4766-AA23-D08180C3910B@gmail.com> In-Reply-To: Mime-Version: 1.0 (1.0) Date: Fri, 23 Dec 2011 18:47:07 -0500 Message-ID: <-1820303040133346119@unknownmsgid> To: =?UTF-8?B?QW5kcsOpIFLDuG1ja2U=?= Cc: John Crenshaw , Stas Malyshev , PHP Developers Mailing List , =?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?= Content-Type: multipart/alternative; boundary=000e0ce0266a39709f04b4cb09a5 Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: will.fitch@gmail.com (Will Fitch) --000e0ce0266a39709f04b4cb09a5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sent from my iPhone On Dec 23, 2011, at 6:32 PM, "Andr=C3=A9 R=C3=B8mcke" wrote: 2011/12/23 John Crenshaw > > From: Will Fitch [mailto:will.fitch@gmail.com] > > > > I would like to take this opportunity to query on a consensus: > > > > Would you prefer to allow methods with type hinted return values to > return null at will, or add a marker noting that it *may* return null? > > > > Example: Return null at will > > > > public ArrayIterator getIterator() > > { > > // something happened, will return null > > return null; > > } > > > > Example: Return only if identified as such > > > > public ArrayIterator? getIterator() > > { > > return null; > > } > > I hate the syntax in the second example (using ?). > It looks strange, but easy to get used to. Two examples from C#: public decimal? Grade { get; set; } public Nullable Time { get; set; } If it is decided that we continue down the road of limiting nullable returns, and want to add an indicator, what about something like this: public nullable ArrayIterator getIterator() If the nullable token isn't declared, it can't return null. > > IMO allowing null should be the default unless specifically disallowed. I disagree for the reasons mentioned by for instance Robert. Type hints should be strict/explicit or not done at all. --000e0ce0266a39709f04b4cb09a5--