Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114983 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33686 invoked from network); 21 Jun 2021 17:16:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jun 2021 17:16:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A5D501804C9 for ; Mon, 21 Jun 2021 10:34:15 -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,NICE_REPLY_A, 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-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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, 21 Jun 2021 10:34:15 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id r9so20583236wrz.10 for ; Mon, 21 Jun 2021 10:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=wRUTisBrmLnTN9afe7v06Y2YU471IfxChfHmmlMS4GI=; b=Xts9cyvG+MGduDjLLm1Sr8p0CYrTKvsq3Oh7afs7MoK1Jkm9FyJG4zla7EPpMX6mhP gonkIWkc+QcxvZjsASoMzL/jTEm+Bm1G9p+JgknahtQTRjmS+vqwdKzEVxRB3HRAYeOI z/SRco7FxgkyWzbMTtjP4cFeob74x1PRnfgkQNjI0n9QpZld4VJzKmoq4ULta2qz6RUy X60UhmHxdsT6jiSLp5MtjHZlPjJ7ls9JZ2wwLq6T41qCg/4fZoLA4qGgwWLOVJ0S9cZd g6A2+8WGtHB9203pP+NrBLE3oDgG+Js13M2W28ovSyaNjVmxiI4dqbQs5QpOQzscsXpg gddg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=wRUTisBrmLnTN9afe7v06Y2YU471IfxChfHmmlMS4GI=; b=lJuTU6sb89gR2SPzwbeNA1GLuhAOKzdixjRtoP/i5eSWfiNcG2p3Kxrvhj/FdmLTOM r0j2ChxGJqXU5u+QpxKtWfOdJUearH76bGIiHNVArn7GhnaP8Dh6xIR6wEzBJe6O2C8p ENx57BUByqDCglK6AmvsO1biaT4Y9QwV8fSw3YkA61WWvqKElsnx4SLQcwzGBF1u9Zgc OAJMjj3vxYVHVkqm8pHUyrv5D0hPcVx/LCKq0MQaXTpxP6AYyjaYl2hNoTaycvV03NQp 7L/4Cx2rUIoujbwcptz8oc1Sj68hxiWQqylJFLTvXM47IFF3FYPFX/GcuWVGjTlMC+qN dtCQ== X-Gm-Message-State: AOAM532axtxNLOg6///kOHjd0L4sQoNNHEAyZMsUoJPc3NklqhqM5Ws4 WJzjgDT/kIEinWOYh7hMLCfmjBuC5Ww= X-Google-Smtp-Source: ABdhPJyMIgIt62GIar1HfH6aIaHZeS/umxv1iQHL00pefiRaHEManjnnmdhnZy3hT3Ixv6SIti+xQg== X-Received: by 2002:adf:82e7:: with SMTP id 94mr1693368wrc.207.1624296853847; Mon, 21 Jun 2021 10:34:13 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id u18sm16651526wmj.15.2021.06.21.10.34.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jun 2021 10:34:13 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <7f2da982-e29b-ccca-bddc-24ae7f4b0390@gmail.com> Date: Mon, 21 Jun 2021 18:34:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [PROPOSAL] Bare name array literals (again) From: rowan.collins@gmail.com (Rowan Tommins) On 21/06/2021 17:54, tyson andre wrote: > In every place where `key` is a valid php identifier > (e.g. can be used in PHP 8.0's named parameters), > I propose to allow `[key: expr]` to be used instead of `['key' => expr]`. This is an immediate "no" from me: it multiplies the ways to write the same thing from 2 to 4, in order to save a few bytes, in a few instances. I think this is something that Douglas Crockford got absolutely right when he simplified JavaScript object syntax to formalise JSON: every valid key can be represented as a quoted string, so if the quotes are always there, you don't need to remember a list of rules about reserved words, allowed characters, etc. > This is useful for shortening long arrays where the keys are known literals, > e.g. > > ```php > return [success: true, data: $data, cursor: $cursor]; > // is equivalent to the following, but shorter: > return ['success' => true, 'data' => $data, 'cursor' => $cursor]; > ``` Although common, this is not a good use of arrays; if your keys are "known literals", they should be fields of some object: return new Result(success: true, data: $data, cursor: $cursor); If you don't want to declare a class (yet), you can use an anonymous object. Rather than yet another way to write arrays, it would be great to have some more powerful syntax for those; currently you'd have something like this: return new class(success: true, data: $data, cursor: $cursor) { public function __construct(public bool $success, public array $data, public CursorInterface $cursor) {} }; Brainstorming, we could perhaps extend property promotion into the "new class" clause, so that you could write this: return new class(public bool success: true, public array data: $data, public CursorInterface cursor: $cursor) {}; Regards, -- Rowan Tommins [IMSoP]