Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120075 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77892 invoked from network); 20 Apr 2023 07:00:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Apr 2023 07:00:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 05F3A1804A9 for ; Thu, 20 Apr 2023 00:00:54 -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, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Apr 2023 00:00:53 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-2f7c281a015so201741f8f.1 for ; Thu, 20 Apr 2023 00:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681974052; x=1684566052; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=wA7oE9ePTwXIRX70HuK2jY4xxydJTdfVZR/ulYv8rBg=; b=kF0VO9GCzR5dl9hQIl4pMYKENHPTc+aQVHUYdbq6uXswYdWW5Jj9sxXB1YvBpKN0d9 kgEoAnq4rgaATzi5bqw1FOa+ex9FKq4GxOxxClKVrfba13MSQs9Icj/wcU6sXe1BtiVc qGYgfp5W7VxJDjYnbsN73DCpbQqnOKg4sP9rhG/V3AZkblyficLI8j+Ez3H9eUfF4rxb i7A7uwEwUVa48dNd6Eppqi+TDF8r4hDml9eXjI/n0OBGNASyXqd3vJAnSxIB3Nj0LXz3 aV9NeNP5HTSXInxIpvBB9to90EFxsix6wSGcjknjon+oIh8+ggZyVbLHCHHMEUGkx68k i/5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681974052; x=1684566052; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wA7oE9ePTwXIRX70HuK2jY4xxydJTdfVZR/ulYv8rBg=; b=gRDRJj+NKxaOqkUFkV/VCPv0FZUFOFGQvyL/hUxrGTLql5kTpBNo8gkhJ/pO+xvCZO n+l63X3EfAynpLhO6xDLyhxAE4sxPyAtskmgq2xPqS/pw1F257C03JeJg08VaEm0yQva DmiRZrberIFZ8EroswYB7BiBVQ9K+g3sEirKrZv2kSCg4ibBUjmPfuVPdo1kQrwKBH5m mNjV3ZLdtDN2IblRo+3IR9ulZO+Awnl7lNDlzjPtk4y05nvaBSlzbGWl90q2cOgCrUuO TfxaBhQ9SUe13GgQuoSQg/hiIEpZszXe8L3DTwx8fEPZj+FKKy9vYC5y5ZZppwyI4Ixj 2WGg== X-Gm-Message-State: AAQBX9eABFnrxtUslhkqoH2nn0vJcU8Bn9lumbimZeKF5ai2tTia2xDb aL4w4oOoDLlsN1+Z69I8k1IRuAgHlzQ= X-Google-Smtp-Source: AKy350ZXAKRn86EE/lnEWRkL/DTcP2fVeAsJ2I48MGyIvLmm6gI0ggB6HD9A1xkcTZeNHDjnnSaeBg== X-Received: by 2002:a5d:44c6:0:b0:2f2:1379:6b18 with SMTP id z6-20020a5d44c6000000b002f213796b18mr388645wrr.9.1681974052016; Thu, 20 Apr 2023 00:00:52 -0700 (PDT) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id o2-20020a5d58c2000000b002fe522117fdsm1126248wrf.36.2023.04.20.00.00.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Apr 2023 00:00:50 -0700 (PDT) Date: Thu, 20 Apr 2023 08:00:49 +0100 To: internals@lists.php.net, =?ISO-8859-1?Q?Tim_D=FCsterhus?= , Larry Garfield , php internals User-Agent: K-9 Mail for Android In-Reply-To: <1b842b25-c038-f647-67e1-b8c986b7d51d@bastelstu.be> References: <687944e3-75ec-446b-bbd6-6d3d6856e864@app.fastmail.com> <1b842b25-c038-f647-67e1-b8c986b7d51d@bastelstu.be> Message-ID: <14DCA246-277A-44EC-B3A5-3809C5BCC7AA@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: rowan.collins@gmail.com (Rowan Tommins) On 18 April 2023 17:48:00 BST, "Tim D=C3=BCsterhus" wr= ote: >I'd rather see only the fat-arrow being allowed=2E Unless I'm missing som= ething, braces with colon is not used anywhere else, whereas braces + '=3D>= ' is known from match() and '=3D>' more generally is already used with arra= y literals [1]=2E Having two similar syntaxes for the same thing is not gre= at when both are commonly needed is not great=2E They need to be documented= and learned by developers=2E I think it makes sense to have an unquoted form here, because the common c= ase is that they are names which analysers can match statically to particul= ar properties, not strings which will be analysed at runtime=2E There are p= lenty of places in the language where dynamic names are allowed, but we don= 't just use strings for the static case: ${'foo'} =3D 'bar'( constant('BAZ') )->{'quux'}(); More specifically, the "name: $value" syntax matches named parameters, and= while you can use an array for that (via =2E=2E=2E unpacking), we don't fo= rce users to do so=2E In fact, the Future Scope of that RFC considered the opposite: using the c= olon syntax in arrays, along with a shorthand for pulling the key name from= the variable name: https://wiki=2Ephp=2Enet/rfc/named_params#shorthand_syn= tax_for_matching_parameter_and_variable_name > If I wanted to put these ideas into a general framework, I think one wa= y to go about this would be as follows: > > - Consider identifier: $expr as a shorthand for "identifier" =3D> $expr= =2E > - Consider :$variable as a shorthand for variable: $variable and thus "= variable" =3D> $variable=2E That would give us: $point =3D ['x' =3D> $x, 'y' =3D> $y, 'z' =3D> $z]; $point =3D [x: $x, y: $y, z: $z]; $point =3D [:$x, :$y, :$z]; $point =3D new Point(=2E=2E=2E['x' =3D> $x, 'y' =3D> $y, 'z' =3D> $z]); $point =3D new Point(x: $x, y: $y, z: $z); $point =3D new Point(:$x, :$y, :$z); $point =3D clone $point with {'x' =3D> $x, 'y' =3D> $y, 'z' =3D> $z}; $point =3D clone $point with {x: $x, y: $y, z: $z}; $point =3D clone $point with {:$x, :$y, :$z}; Rather than making everything use an array or array-like syntax, I would p= robably go the other way and scrap the special syntax for dynamic names, ma= king the whole thing look like a function call, with support for array unpa= cking: $point =3D clone $point with (x: $x, y: $y, z: $z); $point =3D clone $point with (=2E=2E=2E['x' =3D> $x, 'y' =3D> $y, 'z' =3D>= $z]); Regards, --=20 Rowan Tommins [IMSoP]