Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120428 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39953 invoked from network); 29 May 2023 14:36:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 May 2023 14:36:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB8401804D0 for ; Mon, 29 May 2023 07:36:22 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (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 ; Mon, 29 May 2023 07:36:19 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id ADCFB320093A for ; Mon, 29 May 2023 10:36:17 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Mon, 29 May 2023 10:36:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1685370977; x=1685457377; bh=vf3gIIGBEf ZaUnLds4xasYENrQKjpGTQawTftMNS3Is=; b=AwfTyCjY05HT4sdW1MfWQyCdLw O0s6jXX2MWAjVExoGPI7HXvviRc4/qKxaFbnNqatPHhqsVPd7rgT45qXL7PM9o+X cb1V6xx2BSqloPbyrngEIYwSnFoqs0POnrNill+mTXwWAbwjaGwZtmrllzxEwDZ8 LEIYDCLGM858l9ElegpOVBtlf30IO+MxKYmkex20Gesofyum2iqwYtJWMWD5BKFz LhT55/xNykRSseB+JL/ZAPWAjYMZbMQJmksvLFYbBMW0/qxBPpmPNsGwdFyLTCBi 5TFMK4Vkz3uKliWIL332TbSbxUwcOM0AIusTOVqdQCz+JKX/MolAijtPwI3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1685370977; x= 1685457377; bh=vf3gIIGBEfZaUnLds4xasYENrQKjpGTQawTftMNS3Is=; b=j eRk2eCFkQWp2So2FPnLIuQ5jCMoBODX3xTzJmQEvJhpyM473hefES/EyXrT9rIq8 8n8CJc54oQRg16F+gD0X9sWtU1mmbQE6wHFYxJver3hskY7LD4+r85R5ZoNJLNlL VS7fM8WqaI7dHeCxUgvf/lufdJ3eK+sbRdvDnlYpHE1WPpeSvMF5kwps4fKjsAWr fbihc5X84tplL60LqnZPOHPizkQJjzz1yiIrbF3gh5VozjzSe5golSFLXZ1mNv77 cAboGfctupcM//mGFjywfkqM7hXqK24uHH4jAqcFmAUceLC6lMUwQVa9ESU8jq9N C6M/LL6L/Gybcr/YPqnZg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id C425C1700098; Mon, 29 May 2023 10:36:16 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-441-ga3ab13cd6d-fm-20230517.001-ga3ab13cd Mime-Version: 1.0 Message-ID: <280bcea8-9483-4191-80d3-81763a988290@app.fastmail.com> In-Reply-To: References: <799ae864-6e25-4196-a5ce-0d74600a8378@app.fastmail.com> Date: Mon, 29 May 2023 09:35:56 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: larry@garfieldtech.com ("Larry Garfield") On Mon, May 29, 2023, at 6:47 AM, Micha=C5=82 Marcin Brzuchalski wrote: > Hi M=C3=A1t=C3=A9, > > pon., 29 maj 2023 o 11:18 M=C3=A1t=C3=A9 Kocsis napisa=C5=82(a): > >> Hi Everyone, >> >> In the meanwhile, I changed my proposal to use [] instead of {} after= the >> "with" clause due to its better receptance. >> Additionally, I removed support for the shorthand "property assignmen= t" >> syntax (clone $this with [property1: "foo"]) in >> favor the more powerful one where the left-hand side supports express= ions >> (clone $this with ["property1" =3D> "foo"]) >> so that we have more time to decide whether the former one is really >> needed. >> > > So there would be no option to vote on shorthand properties, right? > > Array syntax with all properties as strings in quotes probably means no > support from IDE. > I think this is a really bad move, I'd be against it. I concur, especially with a dynamic list pushed off to future scope. As= is, we're getting less IDE friendliness and a lot more ' characters in = return for making the property name dynamic. However, the *number* of p= roperty names is still fixed at code time. That's an incomplete tradeof= f. Conversely, using the named arguments style syntax (what future scope ca= lls a shorthand, which I don't think is accurate as it's nearly the same= amount of typing) and allowing it to be "splatted", just like named arg= uments, gives us the best of all worlds. The typical case is easy to re= ad, easy to write, and IDE-refactor-friendly. Allowing it to be splatte= d (just like named arguments) means that in the unusual case where you w= ant the number or names of the properties to be dynamic (which is a vali= d use case, but a minority one), you can pre-build an array and splat it= in place, exactly like you can named arguments. Typical: return clone $this with ( statusCode: $code, ); Fancy: $props[strtolower('statusCode')] =3D $code; if ($reason) { $props['reason'] =3D $reason; } return clone $this with ...$props; That approach, taken now, gives us all the flexibility people have been = asking for, reuses the existing named arguments syntax entirely, and is = the most refactorable option. Additionally, the current "property names expression" section shows a ve= ry odd example. It's recloning the object N times, reinvoking the __clo= ne method each time, and reassigning a single property. If you're updat= ing several properties at once, that is extremely inefficient. Dynamic = property names are not the solution there; allowing the list to be dynam= ic in the first place is, and that should not be punted to future scope. I really want clone-with, but this seems like a big step backwards in te= rms of its capability. It may be enough for me to vote no on it, but I'= m not sure. (Pushing clone-with-callable off to later is, I agree, the correct move.) I am also confused by the choice to make __clone() run before with with = properties. I would have expected it to be the other way around. Can y= ou explain (in the RFC) why you did it that way? That seems more limiti= ng than the alternative, as you cannot forward-pass information to __clo= ne() this way. --Larry Garfield