Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127648 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 416841A00BC for ; Wed, 11 Jun 2025 15:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1749655971; bh=Dg7CVXYbFDKPdKEtCMolUv6rkr5CEiMPrRDOb80TMa8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XlAU8S1ZRa2qCqx6byC9ikm0JpRzGdNI3KEE41TUZIB9ebn/JtH9z/Do3QoH49Q8L 7QJxkDIQ/41R68yIfLOJXriLanSSP+v+q3YlnGCClTv76Lx1EkJjeFpAD34Cnqn1Aa 3GBehbKLVOTszHSnaCvnYqKzd+NRRgC297W+vkJboGwEUfmWlJlA8pYtqE1JfLxstc yVqUTg9p3CRV47R1MA7rgVNIAZAHRmDjzvLtMkrnQO0WcFy+xz5wlVNsdDmqBUOcUZ WiYJ65P725Xd/Vr5NYKdW1tU4OybtAmErCDczvPq5hxlsFHEIDE/99UbmalCIZ3ig5 uASskaY1MgRVQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 34F9E18004E for ; Wed, 11 Jun 2025 15:32:50 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, 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 chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 15:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1749656088; bh=AvUBR7pGmy+1BL0WXj4Oo+fR+1tPZiw3fv5GqdNAIso=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=opzGt2k6Ja6V+w9NnZZDBYSc437oPdwnwiPva3vZARBgrCcd4xx8nJSdeYPrBQASX EkxSFi2NbCaB2mMY6+naGXUxXYE56ZrNWa7f7fZpSaVfWTCGhx/jiG1OTskFfFgdrP iIK1az/HcaRpITRCJkvh3BM18XxuemsyCCLZxL84rC5GOFbvncueL1AxRALDFJbjgE rzOZxP72t0SYnPG/tZSXJESTOng64Ok5ywfc6RHI5bqZKZVG1wKmq/8GH8mX9VEtMo o52M/Mztur3sJXscA2MNOTA/fDnGWVi2bD2cpaKJBMK45ypDJw+7MOK+uigU2SbGH6 MI/0CPLzgJBLw== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 11 Jun 2025 17:34:48 +0200 To: Rob Landers Cc: Volker Dusch , php internals Subject: Re: [PHP-DEV] [VOTE] Clone with v2 In-Reply-To: <8f4bdf65-6237-45c8-92a9-82347dfb85a7@app.fastmail.com> References: <8f4bdf65-6237-45c8-92a9-82347dfb85a7@app.fastmail.com> Message-ID: <9745e70a50f08c667a3596829248877a@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-06-08 21:15, schrieb Rob Landers: > So, it seems like this can only be used for things that can already be > cloned? Yes. It's an extension of the existing cloning functionality. > Things which are directly trying to block an identical clone, but would > otherwise be fine with a clone that changes the value (e.g. value > objects) aren’t allowed to use this new feature? > To me, that feels like an oversight in the design. Trying to enforce “singleton” objects to be able to `===` compare them already requires you to take care of quite a number of things (e.g. making the constructor private, disallowing serialization, …) 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 necessary) and then: private function __clone() { } public function withFoo($foo) { if ($this->foo === $foo) { return $this; } return clone($this, ['foo' => $foo]); } To make sure you are only creating a clone when actually changing anything. Best regards Tim Düsterhus