Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127378 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 4F06A1A00BC for ; Thu, 15 May 2025 14:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747317689; bh=0ZqobxeC0odhj921WS8a+7OCSmyUQFa8VE6VPq+wVwY=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Y1SoEFvJ49bqFLfxammwij4n3DprgQ/I5rus9/Dl7whUBY5uT8eY5KFy54vChWMQL 3ByD0nBuGJcD9MHHzx7H0N1zjVsSWZ6hcxLjgs1KiLoOHOflGy41KoWdUEXVA2sfE4 4BgRYPvtWPD1DzqSO18aVY3XAQMP7ng+JJkW4Bim0ZBbjG2ikG/fr6IBpVtM3tSRU7 skY0FTnxVlMRkZjiwqLQdD6ttZ8wbmmPrTcLYt37fnA4PmyRl++eVQCgWU1WxmDsJ2 dyPz/NRWT02XyZZci53Wwlwju/godrK75BTdliUcxGS3hX9hqoonMxITkVCGZ/epv7 IgFIXz/NIsw9w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B244F180088 for ; Thu, 15 May 2025 14:01:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-a1-smtp.messagingengine.com (fhigh-a1-smtp.messagingengine.com [103.168.172.152]) (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 ; Thu, 15 May 2025 14:01:18 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id B0FD511400E4 for ; Thu, 15 May 2025 10:03:28 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Thu, 15 May 2025 10:03:28 -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:subject:subject:to :to; s=fm3; t=1747317808; x=1747404208; bh=bsVe6v618cPjGFEqrcjj3 gw9ngIz4+wuRVvYpGVlwt0=; b=xz9GDlm8hQwCRwkWsTEN12XNwknoUcjTSnk7o phxU8jbmNOmIwV2N9D/W0fQ+VpOOtForCgMS58YvbzDF2ufSxD03gjZGo2TYM8rw MjFUsyeO9HBbqIQTomb2RQ93Y7PQd3iuqWIyxKUwZVlcE/EXiAcEaUxIgQBOEyWY cKxxGEuDlygmKeOCNoAyYc7xg8WuqeFM91fb5+ZDML7KR35ddKwFWE7KH+XhkrXq 6yHj8aVITUBX/cEwjfTenV9BRlB67j5Edk8wHG/8RVwLOK1sfdJZKNsxOamH55yl Wg4yOofxvoLy6mHPM4crLFN/Dho0KBFyH+HV9bvlIj2wEmsWg== 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:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1747317808; x=1747404208; bh=b sVe6v618cPjGFEqrcjj3gw9ngIz4+wuRVvYpGVlwt0=; b=Ol/m68yXT+R2UFD7n RSCnx+X/JfDz0cKpHUHBmPTqIfYhfRUe7qSVdsv2VVmQzhkXRweJ4ITzrhfosixm fjuBxZApD1eUcMRCHWH+tMraO7/FaoePqDp7tVnHTMfARQU0hok653ty+evguTG4 EKW9zmFZR/+hZXAkpHvst8b0M30jpBLBPmpXQgxVVjXEXY05rDcQJdz9YAmksXs5 GsKPKAwpSx3ICOtWrI7QRr2ezoI4ed5F1c6AA0Ydk+wLNwrz9zEhUjruwx40DEds 8u2QCE+qmKWlpphaYrWOc1rDdzkTHd3NjJUUMBI/U36I6N48jQl6zn/Usirt9Pni Ek3Zg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdefuddttdeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthejredtredt tdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeehgeeujedtgeekffej tdeuvdekieeiveegvdejtefhffejueefvddthfejjedtieenucffohhmrghinhepphgvrg hkugdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtoh epuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhi shhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3781170005F; Thu, 15 May 2025 10:03:28 -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: T11f5e8d0f54ccf80 Date: Thu, 15 May 2025 09:03:07 -0500 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Clone with v2 Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Thu, May 15, 2025, at 1:22 AM, Stephen Reay wrote: > I may be missing something here.. > > So far the issues are "how do we deal with a parameter for the actual > object, vs new properties to apply", "should __clone be called before > or after the changes" and "this won't allow regular readonly properties > to be modified". > > Isn't the previous suggestion of passing the new property arguments > directly to the __clone method the obvious solution to all three > problems? > > There's no potential for a conflicting property name, the developer can > use the new property values in the order they see fit relative to the > logic in the __clone call, and it's inherently in scope to write to any > (unlocked during __clone) readonly properties. I did some exploratory design a few years ago on this front, looking at the implications of different possible syntaxes. https://peakd.com/hive-168588/@crell/object-properties-part-2-examples What that article calls "initonly" is essentially what became readonly. The second example is roughly what this RFC would look like if the extra arguments were passed to __clone(). As noted in the article, the result is absolutely awful. Auto-setting the values while using the clone($object, ...$args) syntax is the cleanest solution. Given that experimentation, I would not support an implementation that passes args to __clone and makes the developer figure it out. That just makes a mess. Rob makes a good point elsewhere in thread that running __clone() afterward is a way to allow the object to re-inforce validation if necessary. My concern is whether the method knows it needs to do the extra validation or not, since it may be arbitrarily complex. It would also leave no way to reject the changes other than throwing an exception, though in fairness the same is true of set hooks. Which also begs the question of whether a set hook would be sufficient that __clone() doesn't need to do extra validation? At least in the typical case? One possibility (just brainstorming) would be to update first, then call __clone(), but give clone a new optional arg that just tells it what properties were modified by the clone call. It can then recheck just those properties or ignore it entirely, as it prefers. If that handles only complex cases (eg, firstName was updated so the computed fullName needs to be updated) and set hooks handle the single-property ones, that would probably cover all bases reasonably well. --Larry Garfield