Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116826 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36461 invoked from network); 6 Jan 2022 07:59:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2022 07:59:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A47151804C4 for ; Thu, 6 Jan 2022 01:06:45 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 6 Jan 2022 01:06:42 -0800 (PST) Received: by mail-pj1-f49.google.com with SMTP id r16-20020a17090a0ad000b001b276aa3aabso7792550pje.0 for ; Thu, 06 Jan 2022 01:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RFa3cBhk/hnat8MVUOHp9iS8wCFEGdsV/+uWxeB5MUk=; b=Gpd7ybPyNJhOBc810wAU7rWTXvpwP+ooj6IgS8LTibZYkBclNBkm8PYzpiSmpRtOhE WCcPR+pYcLbh6XT4FMD7sg1YnoNLZxeK82x5fEa5tb6r0k84Z4aVmyjSXEUCQT9igyEu sHA5JTXb7iRFLa41VTWuB27LM7MgkXXalNgWD3GcpGKJ3gpZt5W4dzwxLkliHClZK3Xc dwpiBXqa74hJd1VO2sh2fJWSUjbE2awY9ud3T08opr3ma2oVoXNgHHGDdkZ9mtOeI4pl uGI7hWMIz9bjLUVVBe+I59lNe6hpq5ytcQgqMLEH3uEjuIekNYN914l2FfT6fi2bANCu RL1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RFa3cBhk/hnat8MVUOHp9iS8wCFEGdsV/+uWxeB5MUk=; b=zw8t+ZCtWwnz4dvW/KY8kVVKRM8SwY3RpUijkvTjIq0JlbyU9fvnNL/PjQEzT5r7Px acM+EBp8hEdhQONou3DjNsWYG5oEytXIX+rev/EC9m+HIfDdBHKbjPYUYFvR1VnYmsl3 amUDLI3PnFYiTZM0Jg0srFIOg5E6B1syfGb3CkoSfqo497Gfiw2uSL+upImgpap3iqSr +ZxaL/6n17nyWJJ5wlYZvPp/V2GY6RRn0iBgVCsgUJad/Cku0/3ejzCtHHiyJ5gydtio c5yA0CJZWhdM4txHPhXNS418GrFfNDd0CWCrtOVlAnczdOhB05mkUdxs2DwTA0KzsLLi l4vg== X-Gm-Message-State: AOAM531PDfimj0N6B53ivadWDC4RY91Rljf9iKXviZ42uJdi22xK5oww VD2dV2PU9xgH2X7+fuddF4We0r+cERPR6zaFnfs= X-Google-Smtp-Source: ABdhPJz3cUsm8o4DGhgh8I7Y4VoGNYJouDO5z9b78X++5ZhX8FXl3zcyz8zlmhYOyty97hlyq2nZOh+KeMi+SZS6iDM= X-Received: by 2002:a17:90b:88e:: with SMTP id bj14mr8941187pjb.183.1641460001110; Thu, 06 Jan 2022 01:06:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 6 Jan 2022 11:06:14 +0200 Message-ID: To: Vincent Langlet Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000047813505d4e630ce" Subject: Re: [PHP-DEV] RFC: Stop to automatically cast numeric-string to int when using them as array-key From: arvids.godjuks@gmail.com (Arvids Godjuks) --00000000000047813505d4e630ce Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 29 Dec 2021 at 17:42, Vincent Langlet wrote: > Hi, > > I recently discovered that an array was automatically casting > numeric-string keys to int if it was possible. For instance, the followin= g > array: > > $a =3D ['01' =3D> '01', '10' =3D> '10']; > > Is not an array with the key '01' and '10' but instead consider the secon= d > key as an int. > > This has some implications like the fact that > - array_flip(array_flip($a)) !=3D=3D $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 li= ke > 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 > . This is still a > "concept" > since I never code with C and know nothing about the PHP implementation a= nd > 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. --=20 Arv=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Telegram: @psihius https://t.me/psihius --00000000000047813505d4e630ce--