Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120479 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95733 invoked from network); 30 May 2023 22:04:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 May 2023 22:04:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B23A91804D0 for ; Tue, 30 May 2023 15:04:54 -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-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 15:04:51 -0700 (PDT) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1b01d7b3ee8so30875775ad.0 for ; Tue, 30 May 2023 15:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685484290; x=1688076290; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CV4Nkc62uk6Y4HsIZPEecmXyENy0oCe0q2E4vJ17er8=; b=np/00cXEqokGIrbBf6U8lqV61MumeO93e7Je86YBova5qo1ykj6wkI79VyJRdEf4lL HxVTA+d1sDO4wiwSMedMNo+1CxcxSVvG1K/7/qFlwPcMxodzukk1NNKBnX05HIqq/YWc gc5UclR4r4Xkp2R/UvKeh1fs05ChidjSwi0bzSQV4sHMOjCzpj3mFz8zGDlt2L50QtCX 4khpKQv2abUN2x/KGsyoL4ndsQpqO9o3UrBeJmUva9cz+DVmwyxORxF0c/DQQftSEEA6 dJFZaHrwDN5Iczo/Y+pAnPHx/b3bLZdpsH20Ez6kP80WDpSCAG0fpzHeGAnGrSU5qAaz qccw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685484290; x=1688076290; 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=CV4Nkc62uk6Y4HsIZPEecmXyENy0oCe0q2E4vJ17er8=; b=JTnvkTuHfvaP6rNW4rtLKW4QxyToLthMnTVHHEYm2QJVfoG/gycZu2vpDzT2sru92P k4JyMK49OWwIDwjOxoAjvPXGTMg+TqOBvr6bqPU+OmmRvcRagJHP02Ys4j/UoXu5H/jf 264dw4RELpZIJK9C0sHL9IyaJ/YOY6pSssYUv8uVCaj6i3T1sfwytcpJIIvyme70rxOl BZsDdFYyBs2H4dpPUDo0WxXhEX5j/B3HXWyz7srxz1mz6h5jXj0h/Gj+ZPCv/s6Q/9Kf UKymuBXLS5NamkkH9DBkRYNyOZMQIcq/eiV0Z/C63uVNP4XfQTHq5GiP/lRM6r7q1H68 CPRw== X-Gm-Message-State: AC+VfDy09Ud0tXlP6WNC2Kk2h8dAwHdyeLedvCa2eYk0T9GBRLQl/Vjm JdlTrsMJ7fkzWqQWa8Y6HXHjYv93tSEUAnhld/M4sTrkeZk= X-Google-Smtp-Source: ACHHUZ557CQbKYDNRZS0rNuLT7Hy5xiXNIC8f9WkkH/HECm15o4ajFpUm942934shU8DuY0tjFiREGqHblqrJRuXKYI= X-Received: by 2002:a17:902:a606:b0:1ae:bf5:7a7 with SMTP id u6-20020a170902a60600b001ae0bf507a7mr3115621plq.35.1685484290021; Tue, 30 May 2023 15:04:50 -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> In-Reply-To: <5db38bc4-a6fd-4cb7-b10d-3ad1a590888c@app.fastmail.com> Date: Wed, 31 May 2023 01:04:36 +0300 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000619e5f05fcf06491" Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000619e5f05fcf06491 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 informatio= n > to > > __clone()? > > Not a specific one off hand. It's more a conceptual question. `with` ha= s > 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, i= f > you have to undo something you just did, you shouldn't have done it in th= e > 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 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 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 have the internal validations, operations and also access to private/protected members that are not accesible from where clone is being called. Regards, Alex --000000000000619e5f05fcf06491--