> On Jan 19, 2020, at 19:53, Mike Schinkel <m...@newclarity.net> wrote:
> 
> P.S.  There was also the mention by Levi Morrison that the type[] syntax was 
> a poor one because of ambiguity between (?int)[] or ?(int[]).  I would argue 
> that the latter would likely occur orders of magnitude more often than the 
> former, so I would argue that ?int[] should interpret as ?(int[]), and if 
> they want (?int)[] then the developer should use parentheses.

As a thought, perhaps the syntax '[Type]' for an array of Type. That way, you 
could write ?[int], or [?int], or even ?[?int] and there would be no ambiguity, 
and no need for parentheses since the array brackets would serve that purpose.

If we also wanted to allow typing array keys, this syntax could be extended to 
[string : Type] and [int: Type], and it would continue to remain unambiguous, 
even with nested arrays, and with using a more similar syntax than the docblock 
syntax array<string, Type>. (It might also be reasonable to support both 
variants as aliases of each other.)

Both of these are the syntax Swift uses for arrays and dictionaries, so the 
syntax has precedence from another language. Swift also supports both syntaxes 
as described above ([KeyType : ValueType] is exactly the same as 
Dictionary<KeyType, ValueType>), but the shorter bracket syntax is preferred 
for readability.

-John

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to