Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57068 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25879 invoked from network); 24 Dec 2011 07:40:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Dec 2011 07:40:54 -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.216.42 as permitted sender) X-PHP-List-Original-Sender: will.fitch@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:39959] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/16-16446-50285FE4 for ; Sat, 24 Dec 2011 02:40:53 -0500 Received: by qabj40 with SMTP id j40so5715785qab.8 for ; Fri, 23 Dec 2011 23:40:49 -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 :message-id:references:to:x-mailer; bh=fbqI/DfGraZwRfbeDQNVszqkCzZ1EpItKYThQsP+Ei4=; b=u4jWPYHJ5WqqT5Co6Ft19plowHWuRlmoWXGw5KKiVRuY5iUcvIixuxPd7j0DEHmoWO jXT+Hy2SDhfLfQX2MVxqxDBwntN9DHx3BlEZXlF0zkefAwEycvz9+7SfSVaUXjGhx9UE ds2M4Rumb6suObfSYCQnH3uKVxqSWr3E0t8Hk= Received: by 10.224.42.140 with SMTP id s12mr15344267qae.87.1324712449573; Fri, 23 Dec 2011 23:40:49 -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 o8sm15213102qaj.0.2011.12.23.23.40.46 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Dec 2011 23:40:48 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: multipart/alternative; boundary="Apple-Mail=_D5ED7B11-0560-4552-9024-22FA6F5F519B" In-Reply-To: Date: Sat, 24 Dec 2011 02:40:44 -0500 Cc: John Crenshaw , Stas Malyshev , PHP Developers Mailing List , =?iso-8859-1?Q?=C1ngel_Gonz=E1lez?= Message-ID: <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> To: =?iso-8859-1?Q?Andr=E9_R=F8mcke?= X-Mailer: Apple Mail (2.1251.1) Subject: Re: [PHP-DEV] Return Type Hinting for Methods RFC From: will.fitch@gmail.com (Will Fitch) --Apple-Mail=_D5ED7B11-0560-4552-9024-22FA6F5F519B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 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 =20 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. On Dec 23, 2011, at 6:31 PM, Andr=E9 R=F8mcke 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; > > } >=20 > I hate the syntax in the second example (using ?). >=20 >=20 > It looks strange, but easy to get used to. Two examples from C#: >=20 >=20 > public decimal? Grade { get; set; } >=20 > public Nullable Time { get; set; } >=20 > =20 >=20 > IMO allowing null should be the default unless specifically = disallowed. >=20 > I disagree for the reasons mentioned by for instance Robert. > Type hints should be strict/explicit or not done at all. --Apple-Mail=_D5ED7B11-0560-4552-9024-22FA6F5F519B--