On Sat, 27 Apr 2019 at 00:13, azjezz <azj...@protonmail.com> wrote:
>
> What do you think about adding the `arraykey` type to PHP.


I don't think we should be adding anything to PHP core unless:

* there is a strong case for it being needed.
* we're sure it's not going to cause problems in the future.
* it's clearly the correct thing to implement.
* there's good reasons not to implement it in userland.

I'm pretty sure this idea fails all of those tests, except the last one.

Without generics, it seems the need for an general arraykey type is
low, for me at least. For the vast majority of the arrays I use, I
don't mix key types. All of the entries in an array will be either
0-based incrementing integer keys, string based keys.

I think the Union Types RFC https://wiki.php.net/rfc/union_types has a
high chance of being revisited in the future. As Nikic mentioned in
the PR  we would need to make sure that arraykey would be compatible
with it. That is very hard to get right without having the Union Types
RFC already implemented, as the behaviour around casting is going to
be tricky.

Or, more simply, there are some parts of PHP that can be made better
by adding small bits at a time. I don't think the type system is one
of those parts, and it's better to get the big pieces in place first,
so that the smaller bits will fit accordingly with those.

If you wanted to proceed with it, I think you'd need to find a really
strong reason for why it should be added, rather than just it could be
added.

cheers
Dan

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to