Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115003 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 780 invoked from network); 22 Jun 2021 03:46:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2021 03:46:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D2BCA1804C0 for ; Mon, 21 Jun 2021 21:04:55 -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, 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-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (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 21:04:55 -0700 (PDT) Received: by mail-vs1-f47.google.com with SMTP id x13so10497692vsf.11 for ; Mon, 21 Jun 2021 21:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=+kwIrB6m0x4Bq17EihbcjZfkW2M5lQjVjIueF16RsU0=; b=DGoDudsnPjiNtHsC08iUp4Le/OlS+bOvCpVtcj7yAJ6QidoHIt7qg6IpkEPph1M4si gXKN1Nsk7GGE6NGomO0F4ipMfMaG6adnRUYBnDHgxs8gFARO1XW59VSlAGdPZTIqUjJb Q7oj+FDeerdFehZsOSnuw1UHR+KF6NbAKTGp5xhW75/pdHQboh+1e6ooUVmN/VDDmNtg pxieTm1NEPGvBjAkulZfvRWDqms2HOR1nE25YUWnrxALPAkfUz9nZ9HMR0U6FgL7d/p6 z4sQILMStEmC7QQaehrp/xlwzG1aZgcZrXCkZOMeLY1sARkrTNWJusVeU8USZb74lVFZ Ov9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=+kwIrB6m0x4Bq17EihbcjZfkW2M5lQjVjIueF16RsU0=; b=g7gvFCS1jcbQq5Qiae2JviXLH23inCR8cjCUXOU7MgyyxtPeA8hw+0i9yqHpwjWPdB HecpGOCFr3ABnw+sWTrQ+q8GWlmFz26IxRSyUs64NT+oWUNdRCMsAgS93nBHk4leUS4c /wnC1bXb++5Sk8maycMHxjgPEi/trlcR137QK2/XJQtRh6lyo6ZDVVkIFyml/vumgI99 +qVzXvX7CKzTneHZaWz+gbi66COqPsSF7kvJDLtW2T69dEw6e4zc+rJ6ySpM6CwU8K1J 59rmySowPz4S5DpuzKcVR8gVIKYtui/H8wi8+zMkCFM6cHyqsTcbJkSPXDSWrabYjIa1 m4oA== X-Gm-Message-State: AOAM531sHJibIiyTNsaYBJaPTEzXyhw/ol4wJ7ECcdhnzkhqSgjXAMBm +sYU9xCPW5xh1AgykKA9bzfBgvJy2p6cUhFsfG8= X-Google-Smtp-Source: ABdhPJyxCiGLcSrD1gR1tJDfAP5d7QOH++eruTVIX7jtQxyub3vG5iNYnpOiclRIlrvpQeklupuAJk9NUXY74IlR5iM= X-Received: by 2002:a67:c09c:: with SMTP id x28mr20351054vsi.9.1624334690067; Mon, 21 Jun 2021 21:04:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:3b8f:0:0:0:0:0 with HTTP; Mon, 21 Jun 2021 21:04:49 -0700 (PDT) In-Reply-To: References: <7f2da982-e29b-ccca-bddc-24ae7f4b0390@gmail.com> <2DF8EE9E-8B83-42C0-898D-550FF36F2943@dafert.at> Date: Tue, 22 Jun 2021 09:04:49 +0500 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [PROPOSAL] Bare name array literals (again) From: office.hamzaahmad@gmail.com (Hamza Ahmad) Hi Tyson, Regardless of what others are saying, I personally like your RFC. The reasons are following: 1. Because named keys are valid PHP names, they are resolved at the parsing level. Thus, they will not be validated again and again. Later, no constants are looked for. 2. At the runtime level, no variable location is done. 3. Since all keys are to be passed as PHP names, both single quoted and double quoted strings are not dealt with. Similarly, concatenation operations are not also performed. 4. Because all named keys are strings by default, type checking is not enfo= rced. 5. `key=3D>value` costs 2 characters without spaces. If a keyboard user, like me, wants to make its code easier to navigate, it adds two spaces to either sides of `=3D>` operator. Then, single quoted and double quoted strings have two extra characters, too! Quotes + spaces + assignment =3D: 2 + 2 + 2 =3D 6. If your suggested feature is added, 6 will be reduced to two =E2=80=94 a colon follows a name, and a space follows the colon. Yay= , we have formulated a solution that simplifies keyboard navigation. Yes, the idea of making anonymous classes/objects easier seams also compelling. Since this is a discussion, I propose to use braces `{}` instead of brackets `[]` and follow the pattern that Tyson is suggesting. I know that it is similar to JavaScript, but it will be different in one regard that it disallows the use of strings (regardless of whether they are literals). Because it requires extra effort to perform array-related operations on objects, I prefer these two syntaxes: 1. `array(a: 1, b: 2, c: 3);` 2. `[a: 1, b: 2, c: 3];` Best Regard Hamza Ahmad On 6/22/21, tyson andre wrote: > Hi Mel Dafert, > >> >I would prefer an improved syntax for creation of anonymous objects. Th= is >> >is something which I have been annoyed with, myself.I'd like to see a >> >simple way of creating anonymous objects with typed properties. >> >> Another advantage arrays currently have over anonymous objects is >> destructuring - >> if this was (somehow?) also made possible with objects, this would be th= e >> best of both worlds. >> (Returning multiple named values from a function is also mentioned in th= e >> use-cases of the RFC.) >> I know this works: >> >> ``` >> [ "foo" =3D> $foo, "baz" =3D> $baz ] =3D (array) $object; >> ``` >> >> (Alternatively also using get_object_vars() instead of casting.) >> But we both have to convert to an intermediate array again, and lose the >> type information of the object (eg. for static analysis), so this could >> also be >> made more ergonomic if we want to go down the anonymous object route. > > Ideas for syntax: > > There's `object(foo: $foo, 'hyphenated-key' =3D> $key) =3D $object;`, > but that would require making `object` a reserved keyword, and it current= ly > isn't one. > > - I had suggested using `$x =3D object(foo: $foo);` as a shorthand for `$= x =3D > (object)['foo' =3D> $foo];` > at some point. Feedback was negative for largely unrelated reasons > (stdClass in general). https://externals.io/message/112082 > > `object{foo: $foo}` seems similarly unambiguous by requiring at least one > property but would also require a new reserved word > > Or `({ foo: $foo }) =3D $object;` - On second thought, I'm against that -= that > is very likely to conflict with possible future proposals to parse block > expressions. > (e.g. getting parsed as a label for a goto followed by returning the > variable $foo.) > > `list{ foo: $foo } =3D $object` is unambiguous, I guess > > `(object)['foo' =3D> $foo] =3D $object;` was another idea but that wouldn= 't even > work. > It's already valid syntax that is parsed as casting an assignment to an > object. > > `->{'foo' =3D> $foo} =3D $object;` may be parseable but doesn't make much= sense. > > Thanks, > Tyson > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >