Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120566 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74802 invoked from network); 13 Jun 2023 20:13:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jun 2023 20:13:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 28E85180382 for ; Tue, 13 Jun 2023 13:13:29 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 13 Jun 2023 13:13:28 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 47A9F5C00BD for ; Tue, 13 Jun 2023 16:13:27 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 13 Jun 2023 16:13:27 -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:sender:subject :subject:to:to; s=fm2; t=1686687207; x=1686773607; bh=tEc7kg2scz GI/0CBUQfT+R9FZGvzZfA6xN+U8boJxOA=; b=nkywhtCTZc3zss81hJyMxdXlW2 iPo/sQoh7kx3B9+x3QGRDvbJZ6Kf02p7qRD4v8GRBkQ4JchOuNi8Ng1zOFff2tQB PZDq3iRpjkxvZnshSnnN8pOyb+danj7pVLjYL4Z50YDPTvQaScZHcegzDqZWTHtD Q79OFWJOzNPzNS6UvbHVL+3TUEhnJTE3S2j6XrHDznGTROl/4o215Wf1iWc3R7Ys 3bWvczCQaUVPUocKQR8KIeWyjRku7ao3iAhuPKph/RpUOM730DSpjPH68Vap1XdQ GD1I8vnl/DrZEbnHRIZHh20v3D4vojJC4x4Ky8DM5w316COo85JGom8u3tNQ== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1686687207; x= 1686773607; bh=tEc7kg2sczGI/0CBUQfT+R9FZGvzZfA6xN+U8boJxOA=; b=O Jo8QTWLwsJkbxEyFnaMXcS3D04RcEKpjFhmtvKKrYXobP32Ark26N0m8o+aZbyaP LreF1SS8Gb+Q3x/QHtzf5WXEI4OKdUWTVWz4tAMxTSyzIif5kqMKLvauUf/lMRxY btq8Rkg6T6RpWmIE3UpocqLRMjTyLOkt1lyiNb0kVWK6uduRXyB9l3NXev3GTgd/ 5dABaLjTK8nFBYfbJL9HzF3SWJc0+yBKu0HyRy6eQIiWIvIW5/yYKGIOs2GU+cp4 qTu9imEW39aI5FLrnuHiCwFwcw6T77zc/jsxDenYofnaqYMCZ9ApcnrzxEn7hgC/ t8Q8sCWAuJanULISenj7w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedujedgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E36641700089; Tue, 13 Jun 2023 16:13:26 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-492-g08e3be04ba-fm-20230607.003-g08e3be04 Mime-Version: 1.0 Message-ID: <07b0f341-f062-45fe-ade0-52cf75003895@app.fastmail.com> In-Reply-To: References: <799ae864-6e25-4196-a5ce-0d74600a8378@app.fastmail.com> <280bcea8-9483-4191-80d3-81763a988290@app.fastmail.com> <5db38bc4-a6fd-4cb7-b10d-3ad1a590888c@app.fastmail.com> <39511e44-93cb-4fde-b0ec-ce24ee88f4be@app.fastmail.com> Date: Tue, 13 Jun 2023 20:13:06 +0000 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jun 13, 2023, at 3:51 PM, M=C3=A1t=C3=A9 Kocsis wrote: > Hi Larry, > > In this case, if the `with` happens first, then the new address object= is >> cloned needlessly, but that *probably* doesn't hurt anything. But $n= ewAddr >> !=3D=3D $p3->address. >> > > Yes, I agree with this: "clone $this with ["x" =3D> "y"];" is the easi= est to > mentally model as a shorthand for "$self =3D clone $this; $self->x =3D= "y";". > If we agree with this model, then it would be weird to execute __clone= () at > the end indeed. But I think Nicolas' example explained this fact much > better than I could. :) Also, separating __clone() from the rest of the > clone opcode would be . > > And you are right, some objects may be cloned unnecessarily, which doe= sn't > hurt, but isn't ideal for sure. I should mention that in ideal > circumstances (when all properties are readonly + all of them are > initialized during construction + none of them are mutable internally), > deep cloning is not 100% required, unless only for defensive programmi= ng > purposes. > > Regards, > M=C3=A1t=C3=A9 Where all properties are readonly, and if an object those are *also* rea= donly, and all are assigned in the constructor... Yeah, that ideal case is kinda narrow, and likely will remain so for a l= ong while yet. Whichever order it goes in, that should be documented explicitly and the= reasoning for it included. (Feel free to pilfer my examples above exte= nsively if that helps.) As for the syntax itself, my preferences, in order, would be: 1. clone $foo with (...), where (...) follows named-argument syntax in a= ll its variants and forms, which includes ...$arr. 2. clone $foo with $array, where $array is an honest to goodness assoc a= rray/array literal, created by any means the developer wants. Either of those are equally expressive; the first is, IMO, cleaner and e= asier to read/type, and probably nicer on static analysis tools, but the= y're still both equally expressive. Anything less than that is, IMO, creating unnecessary confusion about ho= w the syntax behaves that will trip up developers left and right. --Larry Garfield