3 ms·
>You start with an _empty_ array, then (somehow) set the third element of that array? That makes very little sense. Well, there's no reason a language could no
by coldtea 7y ago
>You start with an _empty_ array, then (somehow) set the third element of that array? That makes very little sense.
Well, there's no reason a language could not initialize an empty array to some initial capacity, either on declaration or when you add an indexed element.
- kingdomcome50 7y agoI guess my reasoning is that: $arr = [] doesn't appear to be initializing to any capacity. So that after: $arr[2] = "two" I would expect: count($arr) === 1 And honestly, sure. A language could be designed to pad the array with empty values if you specify an index greater than the upper bound (or lesser than the lower bound). I believe a sibling mentioned matlab did something like that. But is that really better behavior or just different behavior? I don't really see an important difference. My point was that the criticism was fairly weak. PHP, indeed, has a very useful abstraction in its concept of "array". Most of the hate should be directed at the name, not the construct.