Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127382 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 EED021A00BC for ; Thu, 15 May 2025 16:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747327634; bh=jDz4Y9kWGy7N3UEo1f65NgIna8KxYG/ls+r13nRLutY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MHgm9uj2ZvwXt7CYqG7d3oaYowN8VRI+93GKqaaoLE8+U/WCMnl26uRQoBgerntQH zKpU92b69mtOeJTU7YfjhpKkbijnyQVtxtbUuOEVB8VwiZwGhvX4xxCcscfMmFrJSC gCzW+uVkXHExzHQYr1wkkHu2puwPGvy6GWegfxDiMPulNRCenxw32D49zxF8M1LSeh II27eF4XkEEsTVoZBffFkv+JFj3ZX5PDE/dbQOuvbsWLcPUm2XYsiLoXeD7vATukIa se8WHIGrT0eKtwBBsvRn2caDCMK7UcLrv+bvA4JL/r/oHTbU2HEmBnDSEg3aQz35Vk p/KHZMzhpiA6Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 12234180057 for ; Thu, 15 May 2025 16:47:13 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 16:47:12 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e694601f624so888951276.1 for ; Thu, 15 May 2025 09:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech.net; s=google; t=1747327763; x=1747932563; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rdXYH/fkgsjpKgFtX86Mc3fWvyt3NPU0QGcFNDwRsOc=; b=mhlnoJZKQ5m6AJnncbnNABrw3BObEi1Wyx1HdKW1nnkLuPJymUt3oDy5mx3uXzSEaU bRx3ocWS8PE/uSk/6EEn68sSvDoS2+Mu0L4z1QfW+ts2sAMCVGBMgV9raZkyU+VdPyeK UXG8vuzTEXkkRecbMwFwpipz0lY26F1PgEd8hZjOGmH+tB+Ro0a0mpADL7gxvCw8XU7n sWHF4bmLNhYXxlJVyPh4nN6WMyuGQnDvBvQNeFyP+0el2jDAIMnS7cH/778bXTIUQ4Sr c/mfRTWTOI//9+WWpAdtx03K+1SPu5U3yVr1rb+rmd6T28irNmVe6KR9SlUD+Lu00ecx CsDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747327763; x=1747932563; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rdXYH/fkgsjpKgFtX86Mc3fWvyt3NPU0QGcFNDwRsOc=; b=pyKATOMrE02t5vSlK72ETN6UNmVDyCgE950mmUmRpQXfaS3OKUkIljoIvkK/47WoLU 8VJm3t83BlQnvOtYbWflUf041wIxrqfHFN15sddKb2/2VU7xalW8sPVOoojTRtMHn1Be c0VZ8vP7AIfraXzvo7lY/ojIkbbnYUT0L1GNSPn5o6yr/+OUHivkqxZlhL68y91WNWfJ zm92l7gYeowb9807wJ2b/T8zwjHdEgTn71jImgMjUzygZ/R4/mn8tm1lucFKGXPCfiCn LpxbVqWPB+iIJtGslG4pXQ0Py/zaLVjcVw5SWFxTv9N9wbyp4zJGXUyyeVsdBEeR8/Cv Ohdg== X-Forwarded-Encrypted: i=1; AJvYcCW0/7sRXDEgULwqNduuKS6nCVkJx0X0+tJ8ufZUqimC7T6gpOAH0UHowYUka0mueqf6GLUGDZRlyl0=@lists.php.net X-Gm-Message-State: AOJu0YwaWg1cJEce7Z/a55xptAJp9iL4G7Zu90ZIXbRiIeLZFUxHKZQm edKAyvvZ6XCj48QX20fROvRjaYQ7Vl+6UbV9D5dRXwfoXgiJyFcSeeH5gd2GWddWpMlAgCFl5iC A/zL1TELZbErv+0h+0IgzTlqpnsg80LuwTfUu2TZ7LQ== X-Gm-Gg: ASbGncsHGxrbuDl81SFCUxeaHCcRPWEO0HyYsXkVTL2Vi2SRYi8Df4M2SuRkGjQWtzW d5bQUmTjWQrDuedFrQOofd/E1e6IgAUfemu/53zfxd3Bxfj5gCd1p0uNN9ZD+ZyE6S8zYSaU5gW HKL0DxkDqXqOqeQ7xm9Lb97iVjbYtwKt1NV5xkaonQ+DlfELOy37MKdVL5B1ho9p0E/2c= X-Google-Smtp-Source: AGHT+IGHv2IYpTLsbRrCI3ErWfQobWVV/jVqK1ubwB0AoNCA3uGeLOJZElpF20yxF14o1IWeN9VpIjPjhwoyftbsgVo= X-Received: by 2002:a05:6902:1026:b0:e79:1283:55eb with SMTP id 3f1490d57ef6-e7b69792d9emr523814276.0.1747327762502; Thu, 15 May 2025 09:49:22 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <266FA35A-15B0-435E-BBFE-1C6926EB0B7E@koalephant.com> In-Reply-To: <266FA35A-15B0-435E-BBFE-1C6926EB0B7E@koalephant.com> Date: Thu, 15 May 2025 18:49:11 +0200 X-Gm-Features: AX0GCFtPONOvHKXpcjL3x9zYo4ki3dD5QySkLFju5Acs_LxbUMS3mIWBifNlqZQ Message-ID: Subject: Re: [PHP-DEV] [RFC] Clone with v2 To: Stephen Reay Cc: Volker Dusch , "Matthew Weier O'Phinney" , php internals , =?UTF-8?Q?Tim_D=C3=BCsterhus?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: andreas@dqxtech.net (Andreas Hennings) On Thu, 15 May 2025 at 13:56, Stephen Reay wrote= : > > > > > > On 15 May 2025, at 16:44, Andreas Hennings wrote: > > > > =EF=BB=BFOn Thu, 15 May 2025 at 08:24, 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 a= fter the changes" and "this won't allow regular readonly properties to be m= odified". > >> > >> Isn't the previous suggestion of passing the new property arguments di= rectly to the __clone method the obvious solution to all three problems? > > > > What exactly should happen then? > > Would the __clone() method be responsible for assigning those propertie= s? > > Or does the __clone() method get the chance to alter the values before > > they are assigned? > > (this would mean they have to be passed by reference) > > I think this last option is the best, because the values in the array > > can be changed without any readonly constraints. > > > > Another option I was thinking of would be to call __clone() after the > > changes are applied, and pass both the original object and the array > > of changes as first parameter. > > But I think this is a dead end. > > > > -- Andreas > > > >> > >> There's no potential for a conflicting property name, the developer ca= n use the new property values in the order they see fit relative to the log= ic in the __clone call, and it's inherently in scope to write to any (unloc= ked during __clone) readonly properties. > >> > >> > >> > >> Cheers > >> > >> Stephen > >> > >> > >> > > > > I would suggest that the __clone method should be directly responsible fo= r making any changes, just as it is now when it comes to deep cloning or re= setting values. > > Yes I realise it means developers need to then opt in and provide the fun= ctionality to support `clone $foo with(bar: "baz")` or whatever syntax is u= sed. I don't really like this. It would mean that if you add an empty __clone() method, it would prevent all of the automatic setting of values. > > If the properties are public properties, there's nothing stopping someone= writing their own clone_with() in userland now; If someone is using reado= nly properties I'd suggest they want to specifically manage updates to thos= e properties themselves anyway. But they already do that in the ->withXyz() methods. A public non-readonly property can be set from anywhere without validation or clean-up, so by default the __clone() method would want to leave it alone. A readonly or non-public property can only be initialized from within the class, so the ->withSomething() method would be the place for cleanup and validation. The default behavior of an empty __clone() method should therefore be to just allow all of the properties being set as they would be without a __clone() method. > > Additionally it means "clone with" would be usable for non-public propert= ies at the discretion of the developer writing their code. This is already the case, because that "clone with" for non-public properties can only happen from within methods of the same class (hierarchy). -- Andreas > > The mental model is also very clear with this: copy the object in memory,= and then call __clone(), with the arguments passed to the clone action - w= hich may be none in the case of code that doesn't accept any clone argument= s. The only change from the current model is that it *may* be passing argu= ments. > > Cheers > > Stephen > > >