Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127387 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 CDF681A00BC for ; Fri, 16 May 2025 08:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747384686; bh=gOCRFNAedG27Imj/V+iJSF31EDlwef4l8w+6PNc4BXE=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=QxFa6JpAI+Dch3jjoybvpiyR/XmRm97BHTk3g3/PucnGrvcZJ0b61JEjP15zXmt11 tBO0hxeFn6GnO7MJdd4yBj06iTfEhKfwzO9TbtOVq+S7QPLzJh9uRE9oDldrY+UA/q nAf9SfUugfLMT9cAvWfB3dLfKT+l4yZFVCRX3YbETBGay91SO8edAuJcbtCKZOOXSI OwVEVbWRoXAB7j/gyY5u3NgRQrDGOuACT08tZO5PJRtTh5Yi+tFX60ztL2RxWZgk/P Yxid3TzphgkJfcWajCJPSm133L/KTvGgKrZgNxSfd/yJ4NlrOBqUWrCamd1pXJtBoF Q6vsUYg74IJkQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53C14180057 for ; Fri, 16 May 2025 08:38:05 +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=1.5 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MIME_QP_LONG_LINE, MPART_ALT_DIFF,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-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 ; Fri, 16 May 2025 08:38:05 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3a1fb17bb8cso1357788f8f.0 for ; Fri, 16 May 2025 01:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747384814; x=1747989614; darn=lists.php.net; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=E4j8+SDRW2NZPxPbcH7TlAQ8Y56KnUkXhYrEmj1GCmU=; b=j00KKDwb3sZ1i6dp7SYZzqJ429jc6QchDUqwg8ZR1nxfzbrzWwOcuxNOFwfRuLXg9F eyXeo+XvZqJXgODEVQBU/KPQfMyPyk1GR2lAcyJ9ykr6oM2b/ST0uzVUm9yRHEuj3TS3 GeOONb5n+5iVcq6z/wN+0nIWZMwMiydu2xkoaCxzti3c/gZGivq/E6M0VmxvVv8BJEzj dNw2rlQDiXqEjIr/nPkuDUrq1pVlnOEz4Eyq6DWd0s9mMSlg9ylaL5vYzpRjGnJWAHPx CK3Oi7Y0rRMziCSPdukvKOOQFwKnie1UnXpmECcKcQMvIFNPc/qnibOQoz4TsuEpI9+P ufkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747384814; x=1747989614; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E4j8+SDRW2NZPxPbcH7TlAQ8Y56KnUkXhYrEmj1GCmU=; b=UtXByP123Dao3T/MLVhSyLaADVIZhSYjg46GxrigE9D6rIUlhEXpVuxKwztKm6YATE Dy1hZkcxaPWMXfMSMlBvB6U6w8a+60XDYyjq+b01NPDU0dhT7+EmWbdtHjff35qoD5up kwXPy6i6OTREjc1dHAYWiykp44OgcnV6IAYwldw1dxv3AlKOuGRrl8Z8+KhwJPndYrYk 98JnVXWB7Va8GnGfjzqYX61nKpsCPePWyIgiLPbUhFcy3X0XCLWVOiomOzS46Beecydc K3kQdc8ehzQAgm54wW9g6dOjLTur7N8Y5x8aetAOXxtCrdsbRMDWpCw4nqQswL93kmDF neDg== X-Forwarded-Encrypted: i=1; AJvYcCViKu7xTykcCDCbc5h1oATvisT3k8JTtIofm9RPoXXDw1hAU3bSN8SgrP9tHoY1O5lF4Msojx9ngVQ=@lists.php.net X-Gm-Message-State: AOJu0YwdMPaLOo6FKdDh45q5+ZoE+nrpMkg3Wl+INVyuRp5gg9PN5L/K em5GMmXybbNz/Q/n0gCpJciOHXBJTTS6wEu3X2PbOI2hqO6Gk32z6SYZ X-Gm-Gg: ASbGnctuSjrZQDJS7r0m9ESTYxJFlIhLTcp3gv90Lj7K5cp/PMRbvzClXXRt8rCrLzp bTZaJBiCxbQCx8B3fKlrcCSh2/JweM7IScURNB9h+8penDtJt9TgOk6kYRYxM3H5UY0SItCH+sJ sBcf5DzZA3iQNcT4t6cI/f9OcBx/HpXz2Zh+3DddetgpQT4qlqyl7kpD7KuwTCHvZkf5F31YCYb Ca4CnXE/K1wOkr1kSsGa0tg9B4ysan4V1c4vXMRu6afg5BJiw9x2DOLltvpg5Q0Be3Qry+qTX71 o312/o6/n/45TsjzB08Abl+KBCIfrTvBTY9GLSRQ8WLU0C10SQAEuLJQNPwaZSSX6EQ= X-Google-Smtp-Source: AGHT+IEV75oCCgnjyzawGmrS46wyAh9zivf5YSp6foDqY1prRulsKsqgtFcOU2ia4+KZ4yQMHQSg+g== X-Received: by 2002:a05:6000:22c6:b0:3a3:582f:efaf with SMTP id ffacd0b85a97d-3a35c83509emr2517664f8f.26.1747384813857; Fri, 16 May 2025 01:40:13 -0700 (PDT) Received: from smtpclient.apple ([188.123.142.122]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a35ca62b1bsm2140625f8f.53.2025.05.16.01.40.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 May 2025 01:40:13 -0700 (PDT) X-Google-Original-From: Dmitry Derepko Content-Type: multipart/alternative; boundary=Apple-Mail-03A9F318-89B9-4469-8E47-7D2EA7DAE22E Content-Transfer-Encoding: 7bit Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] Clone with v2 Date: Fri, 16 May 2025 12:40:01 +0400 Message-ID: References: Cc: Larry Garfield , php internals In-Reply-To: To: Volker Dusch X-Mailer: iPhone Mail (22F5053j) From: xepozzd@gmail.com (Dmitry Derepko) --Apple-Mail-03A9F318-89B9-4469-8E47-7D2EA7DAE22E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
I really like a way with arrays. =
It allows users to combine what properties they want to re-set an= d call the clone function only once. Really good catch. 

=



On May 15, 2025, at 9:09=E2=80=AFPM, Volk= er Dusch <volker@tideways-gmbh.com> wrote:

<= blockquote type=3D"cite">
=EF=BB=BF
On Thu, May 15, 2025 at 12:10=E2=80=AFAM Larry Garfield <larry@garfieldtech.com> wrote:
> Please include this in the RFC.

Done

> The concern is someone calling clone($foo, object: new Thingie())= , which would complain that "object" is defined twice.  Making the firs= t argument named __object sidesteps that issue
> If someone then calls clone(prop: 'new va= l', __object: $foo), that... I suppose would technically compile, but one sh= ould never do that, and I am perfectly happy if that breaks.  Similar f= or if someone called clone(prop: 'new val', object: $foo) if we didn't renam= e that parameter.  No one should be doing that and I am fine if that br= eaks

Yes. I think we're on the same page here. But j= ust to be clear, I'll restate it again with my own words:

Whatever the first parameter (the to-be-cloned object) of the clone()= function is called will be completely inaccessible as a property name. = ;

clone($foo, __object: "bar") will fail (Named par= ameter overwrites previous argument)
clone($foo, ...["__object" =3D= > "bar"]) will also fail. 

While `clone(pro= p: 'new val', __object: $foo)` just works.

For exam= ple, using the current implementation where the parameter is named `object`:=
```
class Foo {
    public int $bar;
}<= br>$x =3D new Foo();
var_dump(clone(bar: 5, object: $x));

// object(Foo)#2 (1) {
//   ["bar"]=3D>
/= /   int(5)
// }
```

--
Volker Dusch
Head of Engineering
=
Tideways GmbH
K=C3=B6nigswinterer Str. 116
532= 27 Bonn

Sitz der Gesellschaft: Bonn
Gesch=C3=A4ftsf=C3=BCh= rer: Benjamin Au=C3=9Fenhofer (geb. Eberlei)
Registergericht: Amts= gericht Bonn, HRB 22127
= --Apple-Mail-03A9F318-89B9-4469-8E47-7D2EA7DAE22E--