Hi,

I recently discovered that an array was automatically casting
numeric-string keys to int if it was possible. For instance, the following
array:

$a = ['01' => '01', '10' => '10'];

Is not an array with the key '01' and '10' but instead consider the second
key as an int.

This has some implications like the fact that
- array_flip(array_flip($a)) !== $a
- array_search('10', $a) is an int when array_search('01', $a) is still a
string. Someone using strict types and passing the result to a function
expecting a string could end with an unexpected crash.

I've created an issue about this https://github.com/php/php-src/issues/7845
but it was recommended to me to send a mail to this mailing list instead.

I don't think this behavior should be considered as "normal" and would like
to propose to change this for PHP 9, as it's a BC-break. To me it can and
be considered as a follow-up of
https://wiki.php.net/rfc/string_to_number_comparison and
ttps://wiki.php.net/rfc/saner-numeric-strings
<https://wiki.php.net/rfc/saner-numeric-strings>. This is still a "concept"
since I never code with C and know nothing about the PHP implementation and
if this change would be possible. Any help is welcome then.

Thanks

Reply via email to