Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72862 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61660 invoked from network); 28 Feb 2014 14:25:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2014 14:25:56 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:60516] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/E4-28957-27C90135 for ; Fri, 28 Feb 2014 09:25:56 -0500 Received: (qmail 15005 invoked from network); 28 Feb 2014 15:25:52 +0100 Received: from heim-033-53.raab-heim.uni-linz.ac.at (HELO RoLaptop) (193.171.33.53) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 28 Feb 2014 15:25:52 +0100 To: "'Philip Sturgeon'" , "'PHP Developers Mailing List'" References: <52D865C7.4070009@sugarcrm.com> <531044A8.8050002@googlemail.com> In-Reply-To: Date: Fri, 28 Feb 2014 15:25:49 +0100 Message-ID: <001f01cf3490$fadf31e0$f09d95a0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQInURIh6Kc6IUZr3EE3x2wBXsr7YAIPrvW7AqmJB/QClDnE9AFyZ2wjAiXcbn8Bu1t+JAEbKtkQAeHLkb8Dk0e8SQIy3L+sAYhJtV6ZYxl3MA== Content-Language: de-ch Subject: RE: [PHP-DEV] Introducing "Array Of" RFC From: php@tutteli.ch ("Robert Stoll") > -----Original Message----- > From: Philip Sturgeon [mailto:pjsturgeon@gmail.com] > Sent: Friday, February 28, 2014 2:54 PM > To: PHP Developers Mailing List > Subject: Re: [PHP-DEV] Introducing "Array Of" RFC > > On Thu, Feb 27, 2014 at 4:34 PM, Marco Pivetta wrote: > > > > > > On 27 February 2014 22:11, Philip Sturgeon wrote: > >> > >> So, should we allow nulls in an arrayof-style type hint? > >> > > > > `null` has its own type, which is mismatching the type required by the > > array-of syntax when requesting, for example, `Foo[]`. > > > > If `null` was allowed in the array, as a user, I'd still be forced to > > `array_filter()` on every call, so it would defeat the new feature > > completely. > > > > Cheers, > > > > Marco Pivetta > > > > http://twitter.com/Ocramius > > > > http://ocramius.github.com/ > > > > I completely agree with you and the other folks saying: "Allowing > nulls would defeat the new feature completely". Personally I would not > see myself using the "Foo or null", and if I wanted to in the future I > could very easily just not type hint the array. > > > On Thu, Feb 27, 2014 at 4:34 PM, Andrea Faulds wrote: > > > > On 27 Feb 2014, at 21:11, Philip Sturgeon wrote: > > > > So, should we allow nulls in an arrayof-style type hint? > > > > > > I previously suggested using the C#-style ? to specify nullability. Why > > can't we do that? > > > > -- > > Andrea Faulds > > http://ajf.me/ > > We could potentially add in the ? syntax later on, if people seemed to > want the feature enough? > Just to make sure we are on the same page here, nullable arrays are > fine. Arrays with nulls inside are not. > > Both of these are acceptable: > > function foo(Bar[] $baz) // accepts [new Bar, new Bar] > function foo(Bar[] $baz = null) // accepts [new Bar, new Bar] or null > > Some people are suggesting the following alternatives. > > 1. Let nulls in there regardless of default var hinting: > > function foo(Bar[] $baz) // accepts [new Bar, null, new Bar, null] > function foo(Bar[] $baz = null) // accepts [new Bar, null, new > Bar, null] or null > > This is what many describe as a completely useless version of the > feature, as array_filter would need to be run to ensure you're only > working with objects of a certain type (which is 90% of the use-case > for this RFC). > > Or, 2. Offer optional syntax for arrays containing nulls > > function foo(Bar[]? $baz) // accepts [new Bar, null, new Bar, null] > function foo(Bar[]? $baz = null) // accepts [new Bar, null, new > Bar, null] or null > > Pro: Keeps nulls out of the array by default, offers a way to say "Bar or null" > Con: Potentially syntax soup. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php I brought up that null in an array is a valid use case at the beginning of this discussion and that the RFC should deal with such use cases - otherwise it is incomplete. I still claim it is incomplete if this topic is not addressed but I am happy if option 2 is implemented later on.