Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71193 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51406 invoked from network); 16 Jan 2014 20:20:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2014 20:20:43 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.240 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.240 imap2-1.ox.registrar-servers.com Received: from [198.187.29.240] ([198.187.29.240:39843] helo=imap2-1.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/E4-21406-91F38D25 for ; Thu, 16 Jan 2014 15:20:42 -0500 Received: from [192.168.0.200] (unknown [176.25.177.94]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 0D18E5A0051; Thu, 16 Jan 2014 15:20:37 -0500 (EST) Message-ID: <52D83F13.3000702@ajf.me> Date: Thu, 16 Jan 2014 20:20:35 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Andrey Andreev , "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: ajf@ajf.me (Andrea Faulds) On 16/01/14 20:14, Andrey Andreev wrote: > Am I the only one who finds both proposed syntaxes somewhat confusing? > > The originally proposed 'Bar[]' simply looks strange. It is, however, familiar to C, C++, C# and Java users. > So, how about this: > > Array[Bar] $a - $a is array containing only instances of Bar > Array[Bar|null] $a - $a is array containing Bar instances or nulls > Array[Bar] $a = null - $a is either null or array containing only > instances of Bar > Array[Bar|null] $a = null - above, but the array can contain nulls That doesn't make much sense as a syntax, IMO. It looks like "Bar" is the index of the Array here. Surely it could use angle brackets, which would be familiar to people who've dealt with generics (C++, C#, Java users): Array $a > It's easily readable and everybody should be able to recognize what this > thing does even without prior knowledge. It's not clear to me at all at first glance. Is that a Bar-indexed array? > Or even (at a later stage): > > Array[]["key1", "key2"] > > ... which would hint for a numeric index array containing associative > arrays that in turn must have the defined keys. This is indeed a bit crazy, > but possible to add in the future without BC breaks. You could even shove > scalar typehints in there as soon as they are implemented. ...that's even less intuitive to me. -- Andrea Faulds http://ajf.me/