On 12/09/2019 15:13, Nikita Popov wrote:
FTR this is basically what Python does via defaultdict: https://docs.python.org/3/library/collections.html#collections.defaultdict
Thanks, I'm glad I wasn't completely daft thinking there might be some way to express it. :)
I think it is the "cleanest" solution to this problem overall. Though it does need a separate structure, rather than our favorite PHP array.
Indeed it does, and I think that's the better route to making PHP a stricter language: before we take away the existing features, add the new ones that let you express things better.
PHP's array type, and its type system in general, allow a lot of very expressive algorithms which are hard to do with more rigid type systems. Modern languages like C# bring back that expressiveness using things like generics, a rich library of built-in collections and interfaces, and so on; they don't just say "sorry, you can't do that".
Regards, -- Rowan Tommins (né Collins) [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php