Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120480 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 826 invoked from network); 30 May 2023 23:53:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 May 2023 23:53:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A14CF180547 for ; Tue, 30 May 2023 16:53:36 -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,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (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, 30 May 2023 16:53:36 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id DAD6632009E3 for ; Tue, 30 May 2023 19:53:34 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 30 May 2023 19:53:35 -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=fm1; t=1685490814; x=1685577214; bh=KPc813RcPJ RrMTmqcKAM6G29VmsHi1hGFxn1xwhWZ6k=; b=RdslpW5Fyb225NhEh5A/s1n6rf Hz+S0xBXvqaBAnwOWHCMOkUlV8FzUAK/BKOaRrBGcylxxsnRVLx4drrp0cTLvfPY X/o/Yg5WO3I68+nO0QLsbIetc8oeyjOrNVpj4anb3xUFParQE4nIP3F+9fUYIJK6 BIHblYatBBwijJ9tPoXDh082bNfiw8SUYWFydix1tuH6cfsEhu4z1y4NO3NEKxqM vsNpG3tLWZGTk6/MjD50gQ/ZLCN2f1JPeH/CZOVmL+rsAcX7agsZlNyS4pTddQrt H/I++d0nCX2X9CEuriVV8Uf130DAd+5BqbGMG5HkCs32qBEkJo42wENTLxAQ== 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=fm1; t=1685490814; x= 1685577214; bh=KPc813RcPJRrMTmqcKAM6G29VmsHi1hGFxn1xwhWZ6k=; b=V oH6k6K+nq8SoaOOwY0BDZztn53bEXlGWIG2epDWv7rDz2FBxVJNJbRzJa60zcuDe CUE/fJoPjhzj1J8pIyqz/tbR7hSpiLoTywQ8wBjVu0yniHJlfxTACfAOFuwKbk1S 5prcigoC2qV7NrQ6YAibOPvN2L63eJLQiAv9sK64AxQZ3gI6WHOotck1RaB+PZVK ex+7imF/FkpKvZ1bs8nB8DqJ8PoIiLgPMzHsguTEmr7/hhrh/ZXFQbUbLOYJKwiQ tnbZcxNy4Vt7pPv8LC45SbqWc/DLucKsXLTz2aY+E7BHvwulp3UEtCjtrdkk3A63 bFCNeNQyWaS+cmut952pA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekkedgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 397951700095; Tue, 30 May 2023 19:53:34 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-447-ge2460e13b3-fm-20230525.001-ge2460e13 Mime-Version: 1.0 Message-ID: <39511e44-93cb-4fde-b0ec-ce24ee88f4be@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> Date: Tue, 30 May 2023 23:53:13 +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, May 30, 2023, at 10:04 PM, Alexandru P=C4=83tr=C4=83nescu wrote: > On Tue, May 30, 2023, 19:39 Larry Garfield wr= ote: > >> On Mon, May 29, 2023, at 11:22 PM, M=C3=A1t=C3=A9 Kocsis wrote: >> > To be honest, the current behavior seemed like the natural choice f= or >> > me, and I didn't really consider to execute the __clone() method af= ter >> the >> > clone assignments. >> > Do you have a use-case in mind when you need to forward-pass inform= ation >> to >> > __clone()? >> >> Not a specific one off hand. It's more a conceptual question. `with= ` has >> more contextual awareness than __clone(), so it should have "first cr= ack" >> at the operation, so that if necessary it can make changes that __clo= ne() >> can then respond to. The inverse doesn't make sense. >> >> The only reason for `with` to come after would be to allow `with` to >> "override" or "undo" something that __clone() did. Generally speakin= g, if >> you have to undo something you just did, you shouldn't have done it i= n the >> first place, so that's a less compelling combination. >> >> This one isn't a deal breaker, but we should be sure to think it thro= ugh >> as it's kinda hard to reverse later. >> > > To me so far also it was natural to assume that __clone is first and o= nly > after that the rest of the operations. > But `with` operations, be it properties assignment or even a closure, = would > run in the context of the caller of clone and sometimes this might be = run > not from a method of the cloned class. > > An example: > There is a class that represents persons of a fictive country/planet. > Each person has many properties but has also a first name and a last n= ame > and there is a rule: the two names must not start with the same letter. > Both names cannot be changed as they are defined readonly. > Creation of new persons can be done using new for new random propertie= s or > using clone to preserve existing properties. But in both cases the fir= st > name and last name are randomly chosen. > If we want to control the last name value during clone that would be > possible using the `with` operation but the logic to allocate a first = name > will only happen in `__clone()`method. > > To be able to achieve this we must have __clone last, as there we have= the > internal validations, operations and also access to private/protected > members that are not accesible from where clone is being called. > > Regards, > Alex I... could not understand that in the slightest. Can you show it in cod= e? --Larry Garfield