On Wed, 29 Dec 2021 at 17:42, Vincent Langlet <misterdevil...@gmail.com>
wrote:

> 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
>

Hello everyone,

This is indeed a pretty sizeable BC break that probably is going to cause
quite a few headaches for people, but it's also one of those things where I
think it's absolutely worth tackling and fixing it.
I never got hit by this personally, but when I use string keys, I expect
them to be kept as strings and not do magic conversions to an integer.
Can't vote, but you definitely have my full support to fix this one.
Probably would need a depreciation period and some warnings for a version
or two.

-- 

Arvīds Godjuks
+371 26 851 664
arvids.godj...@gmail.com
Telegram: @psihius https://t.me/psihius

Reply via email to