Re: Introducing "Array Of" RFC

From: Date: Thu, 16 Jan 2014 20:28:05 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-71194@lists.php.net to get a copy of this message
Okay, so <Bar> for contents and [Bar] for keys, although AFAIK you can't use objects as array keys. These were all random thoughts, I haven't though about it all in depth. Still, I believe it's more intuitive than both previous proposals. On Thu, Jan 16, 2014 at 10:20 PM, Andrea Faulds <ajf@ajf.me> wrote: > > > 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<Bar> $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/ >

« previous php.internals (#71194) next »