Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127650 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 517DE1A00BC for ; Wed, 11 Jun 2025 19:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749668404; bh=WPoa/TWb9gZAe0YFj7/N6SRFJgAzxGqpx7fi7b21swE=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=SQeQV9V8haJBn4laTlgbf71ARg/cl3nFf/DWYbnYhqF2qdUh19BTLGklYcjOIAmog c1vfLmQ6Tyj9TJEVvmOSMGAMD/47W94wufkxapEQuBa6GTxMLnTguhdZz/dpK3KkAH 9Yzwcg9CPIRbckGLa+PDyZvxk7ZLp8bZVYHO9lHN4LY+a53KSpfeZqkVLIY/rVn54V lyWp5eYEGsGAM7iroZBOx9X6qWxQ8tkp7I9DbXvgvimEv42Y+/Evey8hqmAroU7Q2f B6Sz1mP2IhPjEiXf+4K4ii4l6k1d00VTANbrSPyB9MvxjwWJgrFzEzsUgvQK/7KDm7 RSF9eYedv42VA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 328A418005D for ; Wed, 11 Jun 2025 19:00:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Jun 2025 19:00:02 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4AFE225401B4; Wed, 11 Jun 2025 15:02:03 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Wed, 11 Jun 2025 15:02:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1749668523; x= 1749754923; bh=o52rUq+b6dd5so9lypxNLp6EWRDTfK4Kp5mn2EVITBE=; b=Z kOE+KS9PCY0xZyGfc88UmLJgbLRXD5i4xiZpY+OOAVn0Zs/mWAO2xmHS4xmIFu1C x+cB77s3YeNNb86vRVLjg3Sl2xg0iH3yRzjPHjvOEpfUgz9Bzf72DX/MSCjIF15R WQasBU91w9FKSUfPSeI1ouv9Hnsr5ycTdGag1Ib9gmbjIzQojWGX6M21mDFahiMq cD99tOL/uC59r1JP+YWGeUvJmSN5if4qhZ8o24Cxq9CEpXztL0DR/J8TM1ZzlrS/ fBi8bm+uClNGpkn06/T039YifD5mPjrAniElBZ3tozCFYU2MToOhLZ4kvs3lxsav lTCTYfZfZm2sujbf/nFHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1749668523; x=1749754923; bh=o52rUq+b6dd5so9lypxNLp6EWRDTfK4Kp5m n2EVITBE=; b=dFIboxhArsNpjH5BFQ+glpaXtpKSab0LJicN8IGQfcXGIUlbffZ Vg+m4HghBQowzXeefuqp5smfllTgG5f/0YimUizamQglmtQHdjLOZisbCY+UwiNq 2XCgjSi7Y+JIS122RzRCcyQR3Bs+MFR5pavtlmbtKHYMAUDy5kRq1Vcpck8moY6H iKnyFVk7+Sd6X3r+8r5dW+DSsZzC4+x1n/mMUlBnP7nmAUZRkLJBEc2k5rnxn+lI A//4dV1qliEblZIOJ8dBO/HpD4XhEmYrv4ncDqkMKkYmRYIOaxxBAlY77V/bzS5F 28riIJnIPX3evcDqL56+FJXvJSaUlsgCM1w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdduvdelkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefoggffhffvvefkjghfufgtsegrtderreertdej necuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtg houggvsheqnecuggftrfgrthhtvghrnhepieeuteehvddvfeejhffgieehleehhedthfef keejffelgfevvdekudetjeejtddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghp thhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepthhimhessggrshhtvg hlshhtuhdrsggvpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdr nhgvthdprhgtphhtthhopehvohhlkhgvrhesthhiuggvfigrhihsqdhgmhgshhdrtghomh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 760251820067; Wed, 11 Jun 2025 15:02:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T79cb8f78b00f3e3f Date: Wed, 11 Jun 2025 21:01:42 +0200 To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: "Volker Dusch" , "php internals" Message-ID: <13a82e3a-9ba9-4b3e-a732-d31aeaab659a@app.fastmail.com> In-Reply-To: <9745e70a50f08c667a3596829248877a@bastelstu.be> References: <8f4bdf65-6237-45c8-92a9-82347dfb85a7@app.fastmail.com> <9745e70a50f08c667a3596829248877a@bastelstu.be> Subject: Re: [PHP-DEV] [VOTE] Clone with v2 Content-Type: multipart/alternative; boundary=1c33cae4c34541b9ad2cfd1e9f58fc4b From: rob@bottled.codes ("Rob Landers") --1c33cae4c34541b9ad2cfd1e9f58fc4b Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jun 11, 2025, at 17:34, Tim D=C3=BCsterhus wrote: > Hi >=20 > Am 2025-06-08 21:15, schrieb Rob Landers: > > So, it seems like this can only be used for things that can already = be=20 > > cloned? >=20 > Yes. It's an extension of the existing cloning functionality. >=20 > > Things which are directly trying to block an identical clone, but wo= uld=20 > > otherwise be fine with a clone that changes the value (e.g. value=20 > > objects) aren=E2=80=99t allowed to use this new feature? > > To me, that feels like an oversight in the design. >=20 > Trying to enforce =E2=80=9Csingleton=E2=80=9D objects to be able to `=3D= =3D=3D` compare them=20 > already requires you to take care of quite a number of things (e.g.=20 > making the constructor private, disallowing serialization, =E2=80=A6) = and=20 > cloning is no different in that regard. >=20 > Nevertheless you can make `__clone()` private (which means that clonin= g=20 > is only allowed from within the class, no Exception necessary) and the= n: >=20 > private function __clone() { } >=20 > public function withFoo($foo) { > if ($this->foo =3D=3D=3D $foo) { > return $this; > } >=20 > return clone($this, ['foo' =3D> $foo]); > } >=20 > To make sure you are only creating a clone when actually changing=20 > anything. >=20 > Best regards > Tim D=C3=BCsterhus >=20 Thank you, that makes sense. =E2=80=94 Rob --1c33cae4c34541b9ad2cfd1e9f58fc4b Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Jun = 11, 2025, at 17:34, Tim D=C3=BCsterhus wrote:
Hi

Am 2025-06-08= 21:15, schrieb Rob Landers:
> So, it seems like this can o= nly be used for things that can already be 
> cloned?<= /div>

Yes. It's an extension of the existing cloning = functionality.

> Things which are directly t= rying to block an identical clone, but would 
> otherw= ise be fine with a clone that changes the value (e.g. value 
<= div>> objects) aren=E2=80=99t allowed to use this new feature?
<= div>> To me, that feels like an oversight in the design.
Trying to enforce =E2=80=9Csingleton=E2=80=9D objects to be= able to `=3D=3D=3D` compare them 
already requires you t= o take care of quite a number of things (e.g. 
making the= constructor private, disallowing serialization, =E2=80=A6) and 
cloning is no different in that regard.

Nevertheless you can make `__clone()` private (which means that cloning=  
is only allowed from within the class, no Exception nec= essary) and then:

     priv= ate function __clone() { }

   &n= bsp; public function withFoo($foo) {
    &= nbsp;    if ($this->foo =3D=3D=3D $foo) {
&n= bsp;            r= eturn $this;
         = }

       &nb= sp; return clone($this, ['foo' =3D> $foo]);
  &nb= sp;  }

To make sure you are only creating = a clone when actually changing 
anything.

<= /div>
Best regards
Tim D=C3=BCsterhus

=

Thank you, that makes sense.
=
=E2=80=94 Rob
--1c33cae4c34541b9ad2cfd1e9f58fc4b--