RE: [PHP-DEV] Introducing "Array Of" RFC

From: Date: Thu, 16 Jan 2014 20:14:08 +0000
Subject: RE: [PHP-DEV] Introducing "Array Of" RFC
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Am I the only one who finds both proposed syntaxes somewhat confusing?

The originally proposed 'Bar[]' simply looks strange.

HHVM's introduces even more "special characters" (<, >, ?) to parse, looks
a bit like a regular expression and it was even already mentioned that it's
"imported" from C++ ... PHP is not C++, and why should it be?

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

It's easily readable and everybody should be able to recognize what this
thing does even without prior knowledge.

Hell, why not Array[Foo|Bar|stdClass|whocares] ?

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.

Cheers.
Andrey.


Thread (73 messages)

« previous php.internals (#71192) next »