Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127415 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 AB2BC1A00BC for ; Wed, 21 May 2025 14:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747837514; bh=0kdiKtiYZv2wW1oMJrF8H9WzZ9DoTB7crkGUeZkq1oc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Er6+/6MJVZkP7Se/6f4srKzzY6ywntDjl4G7h6x+YCyfpY3CxrKF0pKwSh0nJuZL0 06Kd6dKfOsSoJqLMmU0c/tkG8/lri3xPrsdh4CaOvCBgu81u3AMba+DDTC29XKop9B ZHlRikACpOnftmKLkUvhpDNUYp3ddIYNBM0MXDqfc3P/JWScxtUwF6Ae+YDvaiToY6 9anmEWfJAmjY+ioNm/Wx2/fc2Zf13KRumt363T1YLJ6hPvE8fczyo/yiDFsjazYCJn 1tHeqAb5X3atPCPQcOCsi7V4LlVvFXG0Reiwqj6/Ux8Eok4/S98LZdcrhmhJmTKyOh K3ASW6e/FRk4Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D57CA180056 for ; Wed, 21 May 2025 14:25: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,FREEMAIL_FROM, HTML_MESSAGE,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-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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, 21 May 2025 14:25:13 +0000 (UTC) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-550ea5df252so5735346e87.0 for ; Wed, 21 May 2025 07:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747837640; x=1748442440; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rq6VwU2iandyTwTVwBuWQ9ZVsfZ6dPUAReY37yJ+4cA=; b=Rj9Kvvn87S3JFXl7wF//FCUSsN0qCWRahPBWIM7Qv0C9E3Sh24SRNwFAcvb0NEvr4+ jKZrwzkqvJpsP0hzjUs5Uqd0nA26vzqPzfj5BPpzPxKdg9B9xOEao4gChdyYcNBlGs7E 2fdXZUAC1fT+5deb7h1yE2RdZbNEpASJGiruTNitgVcVep/AiNztkx+aTOw7IsOULEG1 4kSD9E/alNvtyVr/uVB+XGl3Cnw56FpGnwdmGZGDWe1xf7x791p9zkO9RxIoInW0Zjcr oE7fpKqqJScKvwCri0/MtdqFeEclz3mJCKwsUA6YjhBHHWOWW/ftp+CRF/sO3dytNJS9 IEig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747837640; x=1748442440; h=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=rq6VwU2iandyTwTVwBuWQ9ZVsfZ6dPUAReY37yJ+4cA=; b=b7ChpMets58C3ynFk9EcJoORxLnSqSGpkcdfJGaoMdozWFcxWihCEJ0EJ1ustqTz2Q ttJPAHDPYEE6LUyY9Tbgyw5nAmXrSJBJtDJTM9SOugmk+76Oh1JSKUofCzSuEOuOhrIo O7o5gu9ohqw6y1IhZ4fFbKCpMRslFFcNNvEV/pf4tJuCEPe4VE73rRJheeQAC5kIDqcn 3p/qiJ4hYGeWzPmsPdRXerR2frfw0bZPuSsxgxm2NA2OMEPgmboxIxRrEEIb0X/wNIH0 5wDnX4TxhiefxluDSFPq2j5nC8y/TSp8WBAN9HrtomsEISPUKe+thMmiyo0zSKnZsJzJ 1Nyg== X-Forwarded-Encrypted: i=1; AJvYcCXoVAZgtJ2bDxSua4Mqfn0BVQYtdqwEknoj9fN9Ahx0OD5OfsBuIr9GeZ46+6+9pKPWkzRgNX/cl+Y=@lists.php.net X-Gm-Message-State: AOJu0YwlbAmqhEubzi/5kPj8Cz+0B+sAHf3JVI4iQ2Iw/Aw1Sch+aKF6 boMtmX8t4SjC+ErY1Yhu58YG91OTXrsaVdUUvK4lnAHcp+vB/KBvMmQrJx0khIFNGlKs2ZORspP hzrvFQn8Ywjh0gwaVqVGHl38Aqs0kysU= X-Gm-Gg: ASbGncvyHk1+b2SvEwEljFGitbYyqscgsC2xVWXdLvtEeV1wYstxVR+hV+x7kRH1Av/ DvfDwSqSQK1FcMnAISzBjg3Dx4yDN2xtHzO2abjI/MgWEmUCv9ny4Z2rpLPzux1JZs8G++XonDK df9fe6KFMgWFW16GqCgnYZ2dnSTSmr52pnzlmQAKE7Yp0= X-Google-Smtp-Source: AGHT+IGAfRDmCtxbpqWGhmjUYOch0iNxIqC/s1Jt6ZymQ2uoL6JyO2QwyDn6mBWMpjRZgdkBZrAlsxd18gpTZce662Y= X-Received: by 2002:a05:6512:3f27:b0:551:f166:bbb with SMTP id 2adb3069b0e04-551f1661101mr3748255e87.13.1747837640005; Wed, 21 May 2025 07:27:20 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <2f30cae4add309021e18d0f359a1814e@bastelstu.be> In-Reply-To: <2f30cae4add309021e18d0f359a1814e@bastelstu.be> Date: Wed, 21 May 2025 16:27:07 +0200 X-Gm-Features: AX0GCFt_iuYIWTDRDomtLi-1GpxEFExzL_YN9f33YLru7cmCGCWCPZTjyw8eAwk Message-ID: Subject: Re: [PHP-DEV] Re: [RFC] Clone with v2 To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: Volker Dusch , php internals Content-Type: multipart/alternative; boundary="000000000000a85cf50635a62978" From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000a85cf50635a62978 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Tim, Le mer. 21 mai 2025 =C3=A0 16:15, Tim D=C3=BCsterhus a = =C3=A9crit : > Hi > > Am 2025-05-19 12:48, schrieb Volker Dusch: > > We're still looking for feedback on the ...variadic approach to the > > Syntax: > > https://wiki.php.net/rfc/clone_with_v2#open_issues, as we only got one > > reply so far on the topic. > > I was hoping for some additional opinions here before adding my own, but > since this does not appear to happen, adding my personal opinion on this > matter now: > > *Some* property name being completely incompatible with =E2=80=9Cclone wi= th=E2=80=9D (no > matter how the first parameter is going to be called) is a limitation > that should not exist, it feels like a feature that is broken by design > and I think I really would hate it if the documentation of this RFC > would need a =E2=80=9CCaution: It is not possible to reassign a property = called > '$object', due to a parameter name conflict=E2=80=9D. > > Adjusting the signature to `clone(object $object, array > $withProperties)` would not have this problem and I don't consider the > additional verbosity of an array literal to be a problem. Static > analysis tools already understand array shapes and would need > adjustments either way to understand the semantics. > > From an implementation PoV a regular array parameter would also be > simpler, since the implementation would be able to simply pass along the > input array, whereas the =E2=80=9Cvariadic=E2=80=9D syntax needs special = handling to > combine positional parameters with named parameters into a single array > that is then used in the cloning process. > > Syntax-wise there might also be a middle-ground. Similarly to how this > RFC turns `clone()` into a function, the `array()` syntax also looks > like a function call and would naturally extend to named parameters. > While mixing positional and named parameters would probably get complex, > allowing purely named parameters would trivially be possible (without > any function call overhead). It would also allow using the > first-class-callable syntax with `array(...)`, something I would liked > to have in the past. A proof of concept PR is at: > > https://github.com/php/php-src/pull/18613 > > Combining named-parameter `array()` syntax with clone taking a array as > the second parameter would allow for the following, which might combine > the best of both worlds? > > clone($obj, array(foo: 1, bar: "baz", object: "this is not > blocked")); > > Thanks for sharing your insights. This looks a bit far reaching for the RFC= . On my side, my opinion is: don't make clone a function call. I've never missed not being able to call clone as a callback. It's trivial to write a short function using the operator when in need. Nicolas --000000000000a85cf50635a62978 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tim,

Le=C2=A0mer.= 21 mai 2025 =C3=A0=C2=A016:15, Tim D=C3=BCsterhus <tim@bastelstu.be> a =C3=A9crit=C2=A0:
Hi

Am 2025-05-19 12:48, schrieb Volker Dusch:
> We're still looking for feedback on the ...variadic approach to th= e
> Syntax:
> https://wiki.php.net/rfc/clone_with_v2#open_i= ssues, as we only got one
> reply so far on the topic.

I was hoping for some additional opinions here before adding my own, but since this does not appear to happen, adding my personal opinion on this matter now:

*Some* property name being completely incompatible with =E2=80=9Cclone with= =E2=80=9D (no
matter how the first parameter is going to be called) is a limitation
that should not exist, it feels like a feature that is broken by design and I think I really would hate it if the documentation of this RFC
would need a =E2=80=9CCaution: It is not possible to reassign a property ca= lled
'$object', due to a parameter name conflict=E2=80=9D.

Adjusting the signature to `clone(object $object, array
$withProperties)` would not have this problem and I don't consider the =
additional verbosity of an array literal to be a problem. Static
analysis tools already understand array shapes and would need
adjustments either way to understand the semantics.

=C2=A0From an implementation PoV a regular array parameter would also be simpler, since the implementation would be able to simply pass along the input array, whereas the =E2=80=9Cvariadic=E2=80=9D syntax needs special ha= ndling to
combine positional parameters with named parameters into a single array that is then used in the cloning process.

Syntax-wise there might also be a middle-ground. Similarly to how this
RFC turns `clone()` into a function, the `array()` syntax also looks
like a function call and would naturally extend to named parameters.
While mixing positional and named parameters would probably get complex, allowing purely named parameters would trivially be possible (without
any function call overhead). It would also allow using the
first-class-callable syntax with `array(...)`, something I would liked
to have in the past. A proof of concept PR is at:

https://github.com/php/php-src/pull/18613

Combining named-parameter `array()` syntax with clone taking a array as the second parameter would allow for the following, which might combine the best of both worlds?

=C2=A0 =C2=A0 =C2=A0clone($obj, array(foo: 1, bar: "baz", object:= "this is not
blocked"));



Thanks for sharing your= insights. This looks a bit far reaching for the RFC.

<= div>On my side, my opinion is: don't make clone a function call. I'= ve never missed not being able to call clone as a callback. It's trivia= l to write a short function using the operator when in need.

=
Nicolas
--000000000000a85cf50635a62978--