Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57069 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32913 invoked from network); 24 Dec 2011 09:40:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Dec 2011 09:40:54 -0000 Authentication-Results: pb1.pair.com header.from=ar@ez.no; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ar@ez.no; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ez.no from 209.85.160.42 cause and error) X-PHP-List-Original-Sender: ar@ez.no X-Host-Fingerprint: 209.85.160.42 mail-pw0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:52687] helo=mail-pw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 79/C6-16446-42E95FE4 for ; Sat, 24 Dec 2011 04:40:53 -0500 Received: by pbds10 with SMTP id s10so7046195pbd.29 for ; Sat, 24 Dec 2011 01:40:49 -0800 (PST) Received: by 10.68.197.99 with SMTP id it3mr38405628pbc.52.1324719649110; Sat, 24 Dec 2011 01:40:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.68.2.233 with HTTP; Sat, 24 Dec 2011 01:40:27 -0800 (PST) In-Reply-To: <6035C633-F740-4218-BAB9-5771E1500BC2@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> <4EF3BD21.2040301@sugarcrm.com> <-6952580475866195972@unknownmsgid> <4EF3C7F7.9010404@sugarcrm.com> <4841689055873111589@unknownmsgid> <4EF3D18B.7040900@sugarcrm.com> <11CFB4E4-F2DA-4766-AA23-D08180C3910B@gmail.com> <6035C633-F740-4218-BAB9-5771E1500BC2@gmail.com> Date: Sat, 24 Dec 2011 10:40:27 +0100 Message-ID: To: Will Fitch Cc: John Crenshaw , Stas Malyshev , PHP Developers Mailing List , =?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?= Content-Type: multipart/alternative; boundary=e89a8ff1cb181cb95404b4d354bc Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: ar@ez.no (=?UTF-8?B?QW5kcsOpIFLDuG1ja2U=?=) --e89a8ff1cb181cb95404b4d354bc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, Dec 24, 2011 at 8:40 AM, Will Fitch wrote: > In the interest of providing options for an ability to mark a method as > returning null, I have added a new patch here: > http://www.willfitch.com/php/nullable.patch > > This includes a new token "T_NULLABLE". Here are a few examples: > > // This is allowed > private nullable ArrayIterator getIterator() > { > return null; > } > > // This throws an E_RECOVERABLE_ERROR > private ArrayIterator getIterator() > { > return null; > } > > The token/identifier can certainly change, but I want to provide the most > options for the best solution. > This looks fine to me, looks more php like then the C# examples. > > > On Dec 23, 2011, at 6:31 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; } > > > > >> >> 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. > > > For the record; This was not ment as an argument against scalar, and similar type hints ( object, callable.. ) . It was an argument against hinting about something and getting something completely different (null). Happy xmas! --e89a8ff1cb181cb95404b4d354bc--