3 ms·
It is not at all obvious that {...} is better than, say, array(...) for a language that has operator braces {}. PHP's array constructs are a little verbose, but
by mojuba 18y ago
It is not at all obvious that {...} is better than, say, array(...) for a language that has operator braces {}. PHP's array constructs are a little verbose, but they are visually distinguishable and thus are not that bad at all.
{...} as an array/dictionary literal makes more sense in a language like Python, where braces are not used otherwise.
- randallsquared 18y agoIf creating a new language that looked like PHP/C/Java/etc, you could use {} for both blocks and arrays (and assoc arrays, like PHP) by making blocks a special case of arrays, conceptually. Then {0; 1; 2; 3;} would be an array of four elements, and as a bonus it would free up [] for something else. :)
- mojuba 18y agoLike in C or Perl, OK, but that makes both unreadable for humans rather than for compilers, that's what I'm saying. So the reasons behind PHP's array() construct are not trivial.