eloquent / typhax

A flexible PHP type hinting syntax.
MIT License
13 stars 0 forks source link

Updated spec to handle sequential traversables better #46

Closed ezzatron closed 9 years ago

ezzatron commented 9 years ago

There is currently no formal way to specify a sequential array, or iterator.

I've taken to using array<integer,type> since arrays with integer indices in PHP are typically sequential. But others have adopted array<type>, even though this is actually equivalent to array<mixed,type>, which in no way restricts the indices.

After discussions, the best solution seems to be to release a new version of the spec, where array<type>, mixed<type>, ClassName<type> etc. all indicate that indices will be sequential integers. array<mixed,type> is still available for the rarer case where index type is flexible. Additionally, the other edge case of non-sequential integer indices can still be expressed with array<integer,type>.

jmalloc commented 9 years ago

+1

koden-km commented 9 years ago

Nice

ezzatron commented 9 years ago

array by itself will probably need to be assumed to be a sequence also - not sure how I feel about this one, as it differs from the native array type hint's restrictions.