Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111573 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28778 invoked from network); 17 Aug 2020 10:17:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Aug 2020 10:17:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D52761804AA for ; Mon, 17 Aug 2020 02:18:01 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) (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 ; Mon, 17 Aug 2020 02:18:01 -0700 (PDT) Received: by mail-io1-f41.google.com with SMTP id t15so16969926iob.3 for ; Mon, 17 Aug 2020 02:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Szvmo+p29aGZJ5Hj05/PfPufCzri2Zabv6aM9Ih05PM=; b=cS6epHo6jDrP3bL5zeWtyY0tYTtl46H8/XsCQ8QmvSsOZsxgKPpKBtNX6Sy1WE+O9g 12KE5LaHpUUbyWYCdyY+PIyDX9JKol/ExD8DYfxm9J2HDPqSyUYluzzP+N5mH5n2k20F jEWvnysalH5v6EGqegzKQknNfVd6sPK4dFTAtbs/jXTgZKwvBdq2gGcmBeyDpqXmy2s2 0N1R3W7Jvpt8jsfqgFdV8ddF8PWbH0TEAAiGt5+/f1D5SWHYP3Wte3hYC99UTQEKU47Y t5Ou5McIsdmoOZ1BQHWe4s9LqhP4osVlvYzq6HWKkX13YyVcviklY+aoPHXvnoIu3nnt iNog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Szvmo+p29aGZJ5Hj05/PfPufCzri2Zabv6aM9Ih05PM=; b=XHd3XmPjE+JWDqhBJRATszIDB1yxKkn9ZOrLVVrgl0LsgCCzxesGp8mVEoKO6tQWZj yJvh2HdM+Cr6GkHrsQN/RnkhtenZ6fFeFAw0rFMFtxWvgaQd07+vOys0bJUTnk8A6GoW dorsumsMFdZGizb+k53hSakCk8XST7R91hgrTXSzxby08cZ/qrkYjLpR1RVrkkMCnJd0 jl3YLl2SDk8/4LQmZXdRl6suMOx/Ab7ujZmd9j1yHwVYTfmQdDZE0eKpsbqHD26kDUp9 BxNDJ08PBfdMJNL2YoFtEi8RKfYiHzMunn4erWqo5MWNk4z5Urtq/csfQ5TtH7ixtCkE 5izQ== X-Gm-Message-State: AOAM531G/80P6oPdZO94oSvXed+EJkoYZZKXEiZATqo0WZRDQWMyRxJH 1jIZ/S5Bl3rYgH0EzDZehM5D0fQCvupZYndplA6cWcjRm4Y= X-Google-Smtp-Source: ABdhPJytXfJvGI4UKGNcMfsOIrSXDknUy7QmtOU4aMUjxmLCnHbCb0oatf7zlF/XWngciDDLYoHR1KxFPApgPzLgmX8= X-Received: by 2002:a05:6602:1406:: with SMTP id t6mr11853377iov.184.1597655878108; Mon, 17 Aug 2020 02:17:58 -0700 (PDT) MIME-Version: 1.0 References: <747c6d622bbadebf32a8b7dec541c333eeb8776a6ab7ff0784a0b75c8895a646@mahalux.com> In-Reply-To: <747c6d622bbadebf32a8b7dec541c333eeb8776a6ab7ff0784a0b75c8895a646@mahalux.com> Date: Mon, 17 Aug 2020 10:17:44 +0100 Message-ID: To: Internals Content-Type: multipart/alternative; boundary="000000000000168c0705ad0f3ff4" Subject: Re: [PHP-DEV] [Concept] Don't cast keys in array to int From: rowan.collins@gmail.com (Rowan Tommins) --000000000000168c0705ad0f3ff4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 17 Aug 2020 at 05:19, Michael Vo=C5=99=C3=AD=C5=A1ek - =C4=8CVUT FE= L < vorismi3@fel.cvut.cz> wrote: > This seems almost as a bug, strict types should apply also for array key > which is currently not the case. > > https://3v4l.org/epv5s No, it really shouldn't. In hindsight, "strict_types" was a bad name for that directive; it is not a catch-all "make the type system stricter" flag, it changes one specific piece of logic: when passing a scalar value to a function parameter annotated with a different scalar type, should the value be automatically cast, or require a manual cast. There is no function call in that code example, so the directive has no effect. The reason PHP treats $foo[42] as referring to the same element as $foo['42'] is to support this straight-forwardly useful code: $options =3D [ 1 =3D> 'apple', 2 =3D> 'orange', 3 =3D> 'banana', 4 =3D> 'caramel', ]; $selected_option =3D $options[ $_GET['id'] ] ?? 'vanilla'; Casting between arrays and objects is a whole separate issue, and changed in PHP 7.2; the RFC explains the issues quite well: https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts Regards. --=20 Rowan Tommins [IMSoP] --000000000000168c0705ad0f3ff4--