Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120482 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15925 invoked from network); 31 May 2023 04:35:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 May 2023 04:35:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD096180384 for ; Tue, 30 May 2023 21:35:18 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 21:35:18 -0700 (PDT) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1b025d26f4fso36538855ad.1 for ; Tue, 30 May 2023 21:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685507717; x=1688099717; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QTK5cUpb41wagLzE1iIT8A1kWuR6Aujr3l1GF4LHL+Y=; b=lT6TXoIkGDWlAfeMWQ/cpaUsePMY9AkEV0JNvKl61f0nOLNfAg1qR5r9GfLCqOT4AD aK+AaZzpWn5B26+b1ifgeZcOHUdA+Ka6A3LMKTpFH5iumdk/f+PK+WO3sCPhffKS5dxr a/LN6NC57b/iewaz1/87FBBTznejQoU080ztIie6xVZwrh6+Xdwvfw1EJIOC16Zx+P/M q4RmtkHMQ6kpqyizvxEJOboSdWbJVVpLzyyA6n5aHex9JCGwVmtVDOQ9LKIZpWAu+aBz qIcL9fRpdlO+Fhw+fSbi4rd+ftW1rAfKV7eGFBs4yeeOOhQVQ9xlFsUdJbncnT2MR0Tv VaZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685507717; x=1688099717; 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=QTK5cUpb41wagLzE1iIT8A1kWuR6Aujr3l1GF4LHL+Y=; b=WbPZysrQH3m1QvPjYC2CTqZtJhnmB/OaSIP9U344KMMmpWs98vtOhhrFG9sYJMVBjw e2bYqruFkdZr/sEWj7yyJTndzJz9xFy+V/oSGrnJ261BHpREJsYuJuwtnUK7Lt+2pj2z cG59GhBXIPYrZkSZRKXXOTvvXAbOI6mkXW9oHtnmyiw8qxIcLplMfbWbhMXMeTjtDpLt mjCKtzTput7lbXYnN3nWw/dyBPpcaS7Hjec0tzAd4Ib4tjzuti0khdUXehLi/KrPDXgL /Ireb3HbxcPjdUEd0+Xe0262Ui26cHRWAbcIsbGqRUpzAoDp09ueCTtT9Ouqlfq6oXoz ixcg== X-Gm-Message-State: AC+VfDxPL2Sbv/DryW3v6GLgrvCbwvHsBwe1z536D83e8eXWUi9CBqxr 5pevtpLZi37PKOxiOUs8erHpO/HSrQkJ/5+ivZRScV5MA43MOQ== X-Google-Smtp-Source: ACHHUZ4pZ6IxoI53NjPHASStYZefdwxdPQM0FCcNQlVqS7OLB5rarbowkqGE0yl96v1mHthXYDAjHzfurT+/wmSCFWQ= X-Received: by 2002:a17:903:32c7:b0:19c:dbce:dce8 with SMTP id i7-20020a17090332c700b0019cdbcedce8mr5086269plr.15.1685507716981; Tue, 30 May 2023 21:35:16 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <39511e44-93cb-4fde-b0ec-ce24ee88f4be@app.fastmail.com> Date: Wed, 31 May 2023 07:35:00 +0300 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000bcac2e05fcf5d87a" Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000bcac2e05fcf5d87a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 31, 2023 at 2:53=E2=80=AFAM Larry Garfield wrote: > 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 > wrote: > > > >> 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 fo= r > >> > me, and I didn't really consider to execute the __clone() method aft= er > >> the > >> > clone assignments. > >> > Do you have a use-case in mind when you need to forward-pass > information > >> 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 > crack" > >> at the operation, so that if necessary it can make changes that > __clone() > >> 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 speaking= , > if > >> you have to undo something you just did, you shouldn't have done it in > 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 throu= gh > >> as it's kinda hard to reverse later. > >> > > > > To me so far also it was natural to assume that __clone is first and on= ly > > 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 r= un > > 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 na= me > > 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 properties > or > > using clone to preserve existing properties. But in both cases the firs= t > > 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 code= ? > > Sorry for that. Here you go: https://3v4l.org/JIBoI/rfc#vgit.master If __clone would be first, there is no way to enforce the rule that a person cannot have their first name starting with the same letter as last name. Regards, Alex --000000000000bcac2e05fcf5d87a--