Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72861 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58712 invoked from network); 28 Feb 2014 13:53:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2014 13:53:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:55046] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/64-28957-1F490135 for ; Fri, 28 Feb 2014 08:53:54 -0500 Received: by mail-lb0-f170.google.com with SMTP id s7so2717544lbd.15 for ; Fri, 28 Feb 2014 05:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=XYZRH73vQkPrSWfzBpHHMLbzPJ+8zeGDTb8fzPtHs7s=; b=PAJd3Pl2SpemqH8Wdy+dkMFWm+XCqo51nwRcWeFkQz2X3skuUlZGd3Ls+XR6TTN/jf 7Eki5Q/OaP1IeN8wXN+wUqGOdLcjRBDMi5BJiloVAgZ6Q5GNr/elWx7KwEiZPyMwayZW nsJ9RUrD9ezgalyWEvkAnTar2Smuo48pCFLuj7vJYSVW2EOnruKjISIoxF0sEZYyedHV KuZXw0JdB5aS1Rw3ZxObFsk6Kirb4n9HkW3WMJ2N3ZyF2FLOy1aAEtrg43bVrvH9ieYY GvZi94g054U5M63EJeh7mKpn48/ZXsJO0yl3o77mLv+521h5SmpIoURvQlCS0VdUkG8s iIBw== MIME-Version: 1.0 X-Received: by 10.152.87.228 with SMTP id bb4mr11561432lab.15.1393595630819; Fri, 28 Feb 2014 05:53:50 -0800 (PST) Received: by 10.114.66.44 with HTTP; Fri, 28 Feb 2014 05:53:50 -0800 (PST) In-Reply-To: References: <52D865C7.4070009@sugarcrm.com> <531044A8.8050002@googlemail.com> Date: Fri, 28 Feb 2014 08:53:50 -0500 Message-ID: To: PHP Developers Mailing List Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: pjsturgeon@gmail.com (Philip Sturgeon) 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.