Hello Internals,
As Danack has mentioned in the PR comments, i want to discuss this here before writing an RFC.
What do you think about adding the arraykey
type to PHP.
see :
- https://docs.hhvm.com/hack/types/arraykey
- https://github.com/php/php-src/pull/4073#issuecomment-487178779
-https://github.com/php/php-src/pull/2603#issuecomment-487122061 - https://twitter.com/azjezz/status/1121182765385433095
- https://www.facebook.com/groups/2204685680/?multi_permalinks=10157789745805681
GitHub pull request : https://github.com/php/php-src/pull/4073
Weak typing
As Nikita mentioned in the PR, this is an issue that we are facing even with union types.
assuming we have a function named get
with the following signature :
function get(iterable $container, arraykey $index): mixed;
should passing a float
or bool
be allowed when strict_types=0
?
if so, should get($arr, true);
act as get($arr, 1);
or get($arr, '1');
?
Naming
The arraykey
naming comes from Hack, i found it familiar since i am used to Hack, but we have other options :
-
index
-
key
-
offset
Best regards,
Saif Eddin Gmati.