On 13/01/2021 09:16, Pierre R. wrote:
Instead of trying to restrict types that can be used as keys, may be
this should be the time to have enumerables, lists, maps, vectors,
sets, types, dictionaries, ... in PHP standard library ? A third party
tool such as PHP-DS should be part of core API instead of being a
third party extension.
For sure, that's why I mentioned initialisation syntax: if you can't use
objects as array keys, you can't use an array literal to construct any
other object which uses objects as keys either, so they're always going
to look uglier:
Compare:
$map = new Ds\Map([]);
$map->put($object1, 42);
$map->put($object2, 69);
$map->put($object3, 39);
$map->put($object4, 101);
To:
$map = [
$object1 => 42,
$object2 => 69,
$object3 => 39,
$object4 => 101,
];
There's a bunch of other gaps, too: arrays are copy-on-write, can be
used in constants and defaults, etc. If we want people to use something
- anything - instead of arrays, these are the things that only the core
language can provide.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php