Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120541 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47977 invoked from network); 8 Jun 2023 18:16:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jun 2023 18:16:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A52531804F8 for ; Thu, 8 Jun 2023 11:16:03 -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_H2,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-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 ; Thu, 8 Jun 2023 11:16:03 -0700 (PDT) Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-30af86a96b4so706403f8f.3 for ; Thu, 08 Jun 2023 11:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686248161; x=1688840161; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=SzH36OJNCcfOWFCt0G/nP5p7hPq/lCpYZZWkKbs3wXs=; b=Y21mDLa7Hrhg+nO1Zui7Hzq70GgJJOaaEuscaVA5RvmoOho+xC1wyo21OIuVL+0mpY oDdOWm1/Dtr2J+reW6qtKjpw2jLtHZxy9Jf+vz5c5n+Qj5ANora2rCsjYRXRnUOgkIMW A8cYCdJ7vUKunycGgTUO49RAfprPUf6nr7mEVWJJGRtWl9YaIH7IeV1CyVwXOVmJ02jr ewT+JyRLmZT4bSshb9dwNLGwHLdw8LmFfCjBEe0/LnWdjvOFyiqBKxDllCbZD2/57vGE X/iLIYXcxze6XANMKeCQT50IS5FXbEjK4SoVvK4ysEeOooPyzT/1YMJDxodg2YE4QPHv wuHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686248161; x=1688840161; h=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=SzH36OJNCcfOWFCt0G/nP5p7hPq/lCpYZZWkKbs3wXs=; b=Wx+Puq+rV+qgC7EBeqB9mrMEiPhbQmd31GbcBahisC4CJ2m32pvn1cuE1IgWKJj9ki OGZzsd6fPDZ4XZg/jyX8Kbk38dqvgSQ9JA9dYa4I7OFp3Q21twnZzveDp3AzclFK/pVa Jfs/g03ASHr81WXlAOE93I17GXTa3GtslWUc+WRyqD8xwN8O4D08QNiEcybIlUNt2AEU Rj6zApikLIEO6vVYpNRswYGLaN0d9Hxn2AxcxrnBZG89Posf6jgDrHE0gCk86qvw+Y/3 4lPJeKj5C12dCUYwuTFJBDu+/d7WiuvCYHIb6WSypN6cwI8cRRY8xaMCHntm9lSDNVM0 476w== X-Gm-Message-State: AC+VfDwqX+9aA2p9OrHypecHnCAHryEXJWyuOhgdsTy7frNP0edppX23 ncPTrT7+QEk1MUpUe/nlxOA6daX6ZXFsrrk0tp+X++CaWyPD5w== X-Google-Smtp-Source: ACHHUZ7Te2XNCwMXn0fr4uUkvc6myUuxfGdaC8fKsAETaNg6pnyT9awtBE9wou9pCYkul+C5Wzb5p9QdpCUKCzBblmM= X-Received: by 2002:adf:e508:0:b0:30e:3eaa:19e with SMTP id j8-20020adfe508000000b0030e3eaa019emr7308058wrm.16.1686248161075; Thu, 08 Jun 2023 11:16:01 -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: Date: Thu, 8 Jun 2023 20:15:49 +0200 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="000000000000a4e8ae05fda23eac" Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000a4e8ae05fda23eac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > 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 > for > > >> > me, and I didn't really consider to execute the __clone() method > after > > >> 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. `wit= h` > > 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 > through > > >> as it's kinda hard to reverse later. > > >> > > > > > > To me so far also it was natural to assume that __clone is first and > only > > > 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 > name > > > and there is a rule: the two names must not start with the same lette= r. > > > Both names cannot be changed as they are defined readonly. > > > Creation of new persons can be done using new for new random properti= es > > or > > > using clone to preserve existing properties. But in both cases the > first > > > 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 hav= e > > 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. > I'm not sure that's what __clone should be used for. This looks like a perfect use case for property hooks, isn't it? On my side, I would find it unexpected that __clone is called after because that would break cloning expectations: Imagine you have a __clone that does some deep cloning (a much more typical scenario for this construct), Let's say __clone() does $this->foo =3D clone $this->foo; Imagine now that you do: clone $obj with (foo: $bar) I'd expect $obj->foo =3D=3D=3D $bar after this. But if __clone is called af= ter, that won't be true, and I don't see how that could be "fixed" if we swap the order. Would you? Nicolas --000000000000a4e8ae05fda23eac--