Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109676 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88703 invoked from network); 16 Apr 2020 11:49:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Apr 2020 11:49:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 185781804E0 for ; Thu, 16 Apr 2020 03:20:05 -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=-0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, 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: AS8560 212.227.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mout.web.de (mout.web.de [212.227.15.3]) (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, 16 Apr 2020 03:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587032402; bh=g9VTWcb/o4oUVVKD9AhlBTZi2gFaaqc64jtv9k9Q5O8=; h=X-UI-Sender-Class:From:To:Subject:Date; b=TRskKtu87QPdUq2MsToP9gMfJS1HBkl9Crin2Z4czgZYVTJpxx/cGaop1ncveRLro QIjMJHHRFdwmN+WC/PLZ1Y28IsVtkZ7aa0p9vcxCYTiK68sEStqd9rQC6E7hEfSIeM w6OTVoqo6JddnXAAyMoEfpZWVYp9s8PjGfUlAaRA= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.21] ([88.66.220.134]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LcgYZ-1j0f2b2AR5-00k7Xz for ; Thu, 16 Apr 2020 12:20:02 +0200 To: internals@lists.php.net Message-ID: <2b8e5da5-2f21-57a2-7e7d-243c686cc69d@web.de> Date: Thu, 16 Apr 2020 12:20:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Antivirus: Avast (VPS 200415-0, 15.04.2020), Outbound message X-Antivirus-Status: Clean X-Provags-ID: V03:K1:nBPJ+vrkc8IoZX0Ed+vQJtczfiRQxCybGOd4Sp7Ue4Ul58RKdAU c4RYP4q6iyV1WUBHTX1G8dLnXDqnnDnsPiEoOfAyo54YRiikrskW71YMSH0O8ZkqZopiP04 /IvcyTHKfpawfMpmudXJ/EGLWra4nJM5wwNmiV56fXj3Syi5bx06lcqHk5SCAiTlL2WT8NE 2S63lo/dnw89+Q1vdWQEA== X-UI-Out-Filterresults: notjunk:1;V03:K0:HK7MHuWNj3Q=:pe+hmu4UsGUSxoJqnTHwgh b0GBFAyn2B2RM05ZxfrdcaipRFkuZHzR3P6q6bgyeNEb0yIbeXIlHh+nHGSvJSt/QM1fg3D0G 1Jng58Gho6HdL/vHrZtBTxjY6RcRaC77ZWgocRMHK9cD5UXHs4El1KUqbBILWohzMX/ghUMrI O5DOajPRdiGUzuNZKVfoO+fICO5atEkXbIo1JlmXo9q7LVnqP57X0lCeEKkLgggA+j0LRWbJ+ /KamVdUDF2QM0UIzETmSfe/jwkh24XLT/IX4shTf6u+nYrpv9SmcTLhmbCG9seBt+2PJBL3Qx ej/3267mKhfgruLqSPHBiRRvZv/t+4FIACeoqsrbntc3QgEVFcIZzxsz+EXy2JyWNEq7ZKcYd VJMc4oM0sZsUL+SQBF+CxkXNfbqP6IowcFNx/5nMHf5WOpUtWqy9h3hj1JN2N2U+Ud+m2LWRN +OQcqZfHJqvt2ScZLzpyK6WKIpXBxZ3/bjN4BzsAHBBXUNdflJRZq4rRbAde8Oa+b5Vvw7XIE HERpENIHejS1BW0pGP+LSHFzYFmctyVD3qKfYr0nbWO08m4o80QXo64v0u5FneG4yqu1p5FQR 0kXkWbug3uLiwl+EEtEmw36XvtJf14/yDh8d3nQBkJjDJY3mTAvUpC5V5DAZMBsD8ZBBKnIYz 8JYkEN+G64xNRHz+a8X7l7ruScHFi2XZ8um2fd0CQZxZU6OFICjTwxveSHaC/MWiRcDNQp+CS wqAszebi2AT//3pCyXTFi9yxeXNY0wTvw5HklfQYhMbCTWH/Pwb7DgP5536jxvU8MRMSBu5/f 0AsKzsViUqC2Yums2eoBOLFSuPAo4qaTUnJEzXuwtjxgpMcwaMV9Lb9dOqupxdprjAl2HEjyM vSTm3lxZWpILF8iXtGfMBvr7HQVuIh3/SP/qcPjflMk/mYqpR23HuSeeoc9oU2YPQpsnLSbqV Mpzz4QdaALQ8j5uGbuex2jLm4r3bEG7ptbZEbRRK6+fuK/dBx91/8A3v6NgNyEEP+2qG7zF/R wiN4Ecl8fw0LHqUq2vrn89xIZ0PKOaqMqjZEqzy6kf5eVG7Pv5teVo7cTc5xGPSJfPRvSkM2I QZYeFZ+6ZqYk80BxurNxrVS+mQLdiunkdZZOyXtK4G0lYbwMpF4pfEg/Tk/tDEDrC+EKP0tDO ZF7IoCGXKZtvw7Nq26Tt3kMecK/VmHNpeaegaCEvXMG6P7xhYXkMimcCm333vg9qx4g5yXWMF kgYcNltIoCqcdBktY Subject: Type hints in array destructuring expressions From: enno.woortmann@web.de (Enno Woortmann) Hi together, as the voting for the "Type casting in array destructuring expressions" shows a clear direction to be declined (sad faces on my side, I really would've liked it as a feature completion of the casting feature set without the need for a really new syntax, as the parser also already coverred it, but ok, time to continue :D ), combined with a strong interest for the topic "type checks in array destructuring expressions" (as well in the discussion as in the vote) I've set up a first draft of an RFC covering this topic: https://wiki.php.net/rfc/typehint_array_desctructuring The discussion around the casting in array destructuring brought up the idea to perform regular type checks in array destructuring expressions. This RFC proposes a new syntax to type hint a variable inside an array destructuring expression: $data =3D [42, 'Example', 2002]; [int $id, string $data, int $year] =3D $data; The type hints behave identically to the type hints used in method signatures (compare https://wiki.php.net/rfc/scalar_type_hints_v5). This especially includes a behaviour depending on the strict_types directive. Additionally to scalar type hints also object type hints are possible. I've not yet started an implementation draft but I think this one will be more tricky than the type cast implementation approach. As the parser re-uses the array definition for array destructuring expressions (which also leads to the type cast implementation without touching the parser) adding type hints to the definition would also affect other parts of the language eg. something like: $x =3D [int $a, string $b]; would be parsed by the parser. I'm currently not able to grasp the impact of such a change. But that's another topic. Let's focus on the idea itself instead of the implementation first. Thoughts on the first draft? Cheers, Enno