Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114981 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29104 invoked from network); 21 Jun 2021 16:36:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jun 2021 16:36:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C5B4E1804D9 for ; Mon, 21 Jun 2021 09:54:28 -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.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2010.outbound.protection.outlook.com [40.92.22.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 21 Jun 2021 09:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cEwgZ1BoLGdA22n0Zsbqg8/jb1gboagrHRqZqssudjcRwZ50RSXNRa68jDx+8mRGqbQnn+Fg2/Dy11UpijZFk+xkncBY/5SRKvxI1vBH/zYaNwP+oHmVVas6zBLKismvnspXLtRFltZASNwrT85WQrynJQpGtj42m+44VV/87QVTuKGjaboCFgPEMbE4RiCjrUGCgioH0OR5l/S9o5tuJhyOkwoNakJVvqPdzmz0x+57ESmawvqRJQGGKu2xCvZYnKpC/7lLdknFy4xbtusk994w3rP5ez7LU8qob9UHYQuY6g/ZU5Rag3wmDKvgxuWX784fun9xKNzQkBo9vZHxaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NxTL7Ksz+emUEse7QxcV2ziB4NSObvJbWY7oV/B69G4=; b=gJGJtS6dfgMe7oGp0Md0NN91hqXcLskMYjLHEnA15euyQm+jf6KLrhGgvJyw7pjKnLnPcKu8HJWhbBf9Vm0/zkcmejhjNRiD5e6tsD3/BJRpkoMgiXUrA9nMd+pGoRqh8bTSQ9IS80kVZf4vivWOy1S1COziXQH+TK8BWlxQH4Y+zipq10OsAbPa7pkGOKd61TK9nxv0DCF9baPqJIyR2x2SCuEwMZo0RYDkBhDaYuGJl39KPSJbPs1syTj53uInGmOasLY/tAIV8M/k2NB98OQ+KMtk+X6jHEA/EQAvL0WzdZ6Wzc429VwiVJC3Hjwbp/NK3GHU3rQuZK8f/qWDSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NxTL7Ksz+emUEse7QxcV2ziB4NSObvJbWY7oV/B69G4=; b=hJRzrYUNwPWRb81j6T2SFnPA9kVIxdX0i3kYhaJcnCallgjsGuyJDZ0K0WmfCkLugCGd6VFSzyZ0ui5N3lwpsjs0Gc+nIHt0G1WY+c6Fs9loPrWK2JDyP3cQGcW2Ljlf5SJoDI5mTJsFW6jwJB4ZSPtht1AAfZyBJgpCns8hgZIjdhpdk26iFQOXAKGbCFxDxdpWG6ot3rNUYCqQpbJ+qJBewrWLg05THi2rgCzbB7S9vhHA93VRlo+TubCrSb7A3pXdtDdQdFoUwJJO8Nrfo3H+1uIkcVBgp9+9ZfXg6lvLHkQFqsX1E44J8+F7nhPkBMqZtC/5jeFK5voSKJuIxw== Received: from BN8NAM12FT008.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::40) by BN8NAM12HT067.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.10; Mon, 21 Jun 2021 16:54:26 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc66::40) by BN8NAM12FT008.mail.protection.outlook.com (2a01:111:e400:fc66::411) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.10 via Frontend Transport; Mon, 21 Jun 2021 16:54:26 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7%3]) with mapi id 15.20.4242.023; Mon, 21 Jun 2021 16:54:26 +0000 To: "internals@lists.php.net" Thread-Topic: [PROPOSAL] Bare name array literals (again) Thread-Index: AQHXZryCJm/mj5rNokqkQmATCwMJ5g== Date: Mon, 21 Jun 2021 16:54:26 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:7772C771359E96AFA37B3A86E43941B756742F4800258B2F1025C74C646922F7;UpperCasedChecksum:E13D0AD27A300FF6A678A5B675D2896274744BA0E52A5AC1501933F9D81B946B;SizeAsReceived:6656;Count:41 x-tmn: [kNbHZf0PrjX1iY5R2y1DmuvMSHuO+/Z9] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 8be2de41-d848-4191-fe2d-08d934d53a8e x-ms-traffictypediagnostic: BN8NAM12HT067: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: kSuCyS2yqlvxmij/iFLaPckT9vAmp/VnhZlw+hQEUmz5ENhPw4DGW3geECzW7h/NCnYKKPj7d1DwEUy3hnDYaMgLYwb9cGlNZTlOvuA1lMaFvYNTk0w30QzC9iFmNGlyJkx0MRcNrNbfyKBx0HNAzsXVz7eK5rAisqUZLzqkw2mU7hHb6pMeeAk3xuJpBf364YHufA+ZLIY3Xot5BcFprYkI1hTaOGwgkwAaEdUrFpMlrmYR09/cfrpdtx4GH4AuiHUZIPSWRc1pH5CXIHm2p+g0BzkKq1fXXmx2k2OSL45UzkDBAVcvR/9LsnTBmdkbXMVDGcelcAwsPBFQGHX2Gh9sV8wQsU+S8q/LiPVL/p0Nf3G76tp7ZzjgejGylZtFnQQgcgeCkAjblmih77yd8maAxP9MyO3oUrRY+a76rqbHRGmXLFeZXA20U8kw6T74qA45gSnuQ93XHs/1es27GA== x-ms-exchange-antispam-messagedata: b6g2DoIShmd+4F76a7EvVbcg3tXa4ni6sabu4OoF36twE6miOAqdCjS96Wq1oV4vphMHniEbpDJfYuSo01AA554dP6aehjWRvGWl5ttHb/YO0VNt53set4B7DiCrLVA69zS2/QQLnxHc//Iz/3NyyA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT008.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 8be2de41-d848-4191-fe2d-08d934d53a8e X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jun 2021 16:54:26.3904 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM12HT067 Subject: [PROPOSAL] Bare name array literals (again) From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= In every place where `key` is a valid php identifier=0A= (e.g. can be used in PHP 8.0's named parameters),=0A= I propose to allow `[key: expr]` to be used instead of `['key' =3D> expr]`.= =0A= (including `list(key: expr)` and `array(key: expr)`=0A= (This can be mixed anywhere with existing key/value syntax such as `$key = =3D> $value`, `...`, etc)=0A= =0A= The implementation can be found inathttps://github.com/php/php-src/pull/663= 5=0A= =0A= This is useful for shortening long arrays where the keys are known literals= ,=0A= e.g.=0A= =0A= ```php=0A= return [success: true, data: $data, cursor: $cursor];=0A= // is equivalent to the following, but shorter:=0A= return ['success' =3D> true, 'data' =3D> $data, 'cursor' =3D> $cursor];=0A= ```=0A= =0A= This uses a similar syntax to named parameter invocations,=0A= making it unlikely to cause future parser conflicts.=0A= =0A= ```php=0A= // Invoking a function with PHP 8.0 named parameters.=0A= process_api_result(success: true, data: $data);=0A= ```=0A= =0A= This can also be used in the older `array()` value and `list()` destructuri= ng=0A= syntaxes. Forbidding `key: value` there seemed like=0A= an unnecessary restriction that would make=0A= the language harder to remember and a language specification a bit longer.= =0A= =0A= I haven't written up an RFC yet, but an older RFC for PHP 5 https://wiki.ph= p.net/rfc/bare_name_array_literal=0A= includes most of the arguments I plan to make, as well as the PR descriptio= n. Things that have changed since then include:=0A= =0A= - In php 8.0, named parameters were already added, so the `key: expr` synta= x is not likely to cause conflicts with future syntax.=0A= - Users would already be familiar with this syntax and its meaning due to n= amed parameters.=0A= - There are better open source static analyzers to detect misuse of array k= eys or passing unexpected types to arrays (Phan, Psalm, PHPStan) when code = is properly annotated=0A= =0A= https://wiki.php.net/rfc/named_params#shorthand_syntax_for_matching_paramet= er_and_variable_name mentioned this among the future scope.=0A= It had also suggested `:$var` or `=3D$var` as shorthand for `var: $var`, bu= t this is going to be left out of this feedback - https://externals.io/mess= age/101698 has mostly negative feedback on a recent proposal (and there are= multiple syntax candidates)=0A= =0A= Any feedback?=0A= =0A= Thanks,=0A= Tyson=