Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116827 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49274 invoked from network); 6 Jan 2022 09:26:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2022 09:26:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9BE0B180511 for ; Thu, 6 Jan 2022 02:34:39 -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.8 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 02:34:39 -0800 (PST) Received: by mail-wm1-f46.google.com with SMTP id n19-20020a7bc5d3000000b003466ef16375so3446805wmk.1 for ; Thu, 06 Jan 2022 02:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:cc:subject:user-agent:in-reply-to:references:message-id :mime-version:content-transfer-encoding; bh=0fiQBtIVAGdwqCHLp3LUMMuUHVjx5FfQYmYYpYnQiFg=; b=iys3ElmAh1Ov2wwO8m47KtDog3NaWfrUtMXTXcP3sjI2aWb2XXMaMozDdt/1YIv6+2 A9YXRaAGoyttuGxRsEsduoTM1z4z9N4crpqGRZCb8Eqa1RHUix1Qzi1gMZlwxYLypKOP eZrBEgiUDE4BXeN31ytID0mwg4COtds3EckPPO8mHJ0SclyOpgj85/UbT7+uYpmAaT9k Syx6pHb3kwSY+76qgknFwiiywK+Bk2Hf2CdWcrZMOw/DIMDbi4xQEMUYrllPaiPjt4we alIbY0j8/7z+VqYLf3dbkNF9E1tZMWCYNx/IeQT2WxAClkxV7ZuaH81aLfbKLHkQH9W6 ojcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:cc:subject:user-agent:in-reply-to :references:message-id:mime-version:content-transfer-encoding; bh=0fiQBtIVAGdwqCHLp3LUMMuUHVjx5FfQYmYYpYnQiFg=; b=16XJr3J0UK1Bn5fZgSBuXHmLTy0zCxAcMkU9plwAWs0JXBPUGAwzo9PDbW235pLlqK I4+oWoPyOS9ohZf4luUAKpeDnuQccOLn95n7ssdasjH8JNmPdE1AyQK8N9WCuoTjLffZ uwA4NuBNIhqbj5xcAnmzd+WVu1R4+lJeGBDJegkpVIXoshfXqriuoywJIIY6auav/RYx PeL4D7tIX7X9EMx4kkFsB5fO/sgW5cV1rgum6hZ6IjuaGiWEVNvKPwsqrlBivE+/KlDV 90Eq7z8bhoui5c/qGPTQhz0PjNXqbHT59YlQFmmDOItpb7JAww9Ny64XIjTPA4drM3eR BKTw== X-Gm-Message-State: AOAM532f07o/8euit3iuR1088bF3D4GXwJv0qcLHEtLGk3kezzEMBlYa SrC5JLDXMVLxl+Q+9ashcmUyOTu1v0g= X-Google-Smtp-Source: ABdhPJxp7MtFvy5lU44pQLiMpyV4oecddyD6xYb5DVtj2lDtd4M4Q4ipNPnjEvbXedhBYSQ2+texzA== X-Received: by 2002:a05:600c:294:: with SMTP id 20mr6430537wmk.7.1641465277754; Thu, 06 Jan 2022 02:34:37 -0800 (PST) Received: from [127.0.0.1] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.gmail.com with ESMTPSA id u12sm1633035wrf.60.2022.01.06.02.34.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Jan 2022 02:34:37 -0800 (PST) Date: Thu, 06 Jan 2022 10:34:32 +0000 CC: PHP Internals List User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <3BC1462F-BC9D-43AF-B4C9-8D988067A5B6@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=----J4UZQC0ZZEM2940OHZA44MZ4VFC0IO Content-Transfer-Encoding: 7bit Subject: =?US-ASCII?Q?Re=3A_=5BPHP-DEV=5D_RFC=3A_Stop_to_automatically_cast_nu?= =?US-ASCII?Q?meric-string_to_int_when_using_them_as_array-key?= From: rowan.collins@gmail.com (Rowan Tommins) ------J4UZQC0ZZEM2940OHZA44MZ4VFC0IO Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 6 January 2022 07:29:58 GMT, James Titcumb wrote: >Just thinking out loud, being able to identify an array type might be a w= ay >forward here (using "syntax" already in use by static analysis tools in >docblocks, for familiarity), e=2Eg=2E > >private array $property; > >This might "turn off" the automatic type juggling behaviour, for example= =2E >If the existing strict_types=3D1 mode is on, this might fail: > >$this->property[3] =3D "hi"; > >If strict_types=3D0 or not declared, the key would be cast to a string=2E Yes, something similar occurred to me earlier, and I honestly think that s= ome new types like this are the only way this can practically be solved=2E >That said, I know there has been contentious discussion on this and the >related topic of generics multiple times, so don't really want to stir up= a >hornet's nest there=2E It's not so much that generics are contentious, but that they're really, r= eally hard to implement within the context of PHP's other features=2E It ge= ts complicated really quickly when you need to verify parameter and return = types, e=2Eg=2E to decide if a value of type SortedList meets a= parameter constraint List Leaving that aside, though, an array type that has certain constraints on = assignment might be workable=2E And a simple pair that only constrain their= keys could just be individually named rather than introducing generics=2E As for the original suggestion, I think some people are underestimating ju= st how disruptive changing this could be=2E The really big problem is that = there is nothing to deprecate, very little to detect with static analysis t= ools, and very confusing code if you want to support both versions=2E The following would be perfectly valid PHP both before and after the behav= iour change: $a =3D []; $a[42] =3D true; $a['42'] =3D false; $a[ (string)43 ] =3D true; $a[ (int)'43' ] =3D false; None of those lines is "wrong", in and of itself, so there's nothing to ma= rk deprecated or warn about; but the result in current PHP is [42 =3D> fals= e, 43 =3D> false]; and with the proposed change, the result would presumabl= y be [42 =3D> true, '42' =3D> false, '43' =3D> true, 43 =3D> false] I can't think of any way one could prepare for this change, other than put= ting a string cast in front of every array index throughout an entire code = base, *and* on every use of array_keys, foreach, etc that *reads* array key= s=2E Unless someone can present a fully working migration plan, this would = get a "no" vote from me=2E Regards, --=20 Rowan Tommins [IMSoP] ------J4UZQC0ZZEM2940OHZA44MZ4VFC0IO--