4 ms·
Is it really useful to have ordered map as the "only" collection type? I guess it might be Stockholm syndrome - but I'm quite comfortable with a "list/array" t
by e12e 5y ago
Is it really useful to have ordered map as the "only" collection type?
I guess it might be Stockholm syndrome - but I'm quite comfortable with a "list/array" type (numeric keys, ordered) and a "map/hash_map" type (objects as keys).
Especially give that with phps "power" you can:
$array = array(
1 => "a",
"1" => "b",
1.5 => "c",
true => "d",
);
var_dump($array);
Ouputs:
array(1) {
[1]=>
string(1) "d"
}
https://www.php.net/manual/en/language.types.array.php https://www.php.net/manual/en/language.types.array.php
- deleted 5y ago[deleted]
- FriedrichN 5y agoThat's indeed a case where it fails, but in all my years I have maybe ran into that problem once. But it's trivial to implement a more strict form of array if you wish. And if I remember correctly there are some standard extensions that have classes to do just that. And for the record, it's not Stockholm syndrome, I use plenty of other languages and I know the benefits and drawbacks of each of those.