Re: Introducing "Array Of" RFC

From: Date: Thu, 16 Jan 2014 20:20:35 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


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/

Thread (73 messages)

« previous php.internals (#71193) next »