Hello! > > Before I create an RFC or attempt a reference implementation, is there any > interest in adding (and then obviously supporting in perpetuity) a list > type? > > The first line of PHP's documentation for "array" states: "An array in PHP > is actually an ordered map". There are some optimisations that make arrays > with ordered integer keys faster, but I'd be interested in a separate type > dedicated to *sequential* integer keys. Such a type would presumably > consume a little less memory. > > Why "list" and not "vec" or similar? "list" is also a reserved word – I'm > imagining that you'd construct a list like > > $l = list["a", "b", "c"]; > > I imagine such a "list" type would be a subtype of "array" – everywhere > that array was accepted, a list would be also, and it would have the same > copy-on-write behaviour. > > If people are interested in having that type, there's a question of what to > do with > > $some_list["a"] = 5; > > Would you convert the $some_list to an array, or throw an exception? > Converting to an array would seem the more PHP-like thing to do. > > Similarly, the behaviour of > > $some_list[$key_out_of_current_range] = 5 > > would be a matter of debate too – would that turn $some_list into an array, > or would it fill up any preceding entries in the array with null? > > What other questions are there? Is a "list" type even a good fit for PHP, > given most of its users seem pretty content with the current > swiss-army-knife array type? > > Best wishes, > > Matt
First, thanks for taking your time to bring some ideas. One of the biggest problems with PHP arrays IMMO is that they are suited to everything therefore optimized for nothing. At least a contiguous list type, AKA real array, could give us some opportunities. But AFAIK adding another real type (not just a pseudo type) on the engine comes with a cost. So, it would make no sense to add a list type and incur in the same type juggling array already has. I'm not sure if I'm in favor of having this new type, but certainly not in favor of allowing the list to become an hash map by key assignments. One could always `$array = [...$list]` or even `(array) $list` explicitly, perhaps. Ty, Márcio -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php