Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111825 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20579 invoked from network); 3 Sep 2020 16:35:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 16:35:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 35CF018053B for ; Thu, 3 Sep 2020 08:40:11 -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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Sep 2020 08:40:10 -0700 (PDT) Received: by mail-ot1-f45.google.com with SMTP id g96so3076958otb.12 for ; Thu, 03 Sep 2020 08:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=XhFEgnfA9ZxmDd3zLKeNoNp8dplALMVZBHsfpQz5V0A=; b=gpxnv/8/PlL1u0O3c7oheKFwniwH1mALAb0yrx6ELD92jD8E1hSec0lotHtVRvkuMm BXEmewhPf0Vrzxa1kFeKqBB5CdwM9x+Tp9RkNAkhTKA3N7UFRsQL5HrvQ6+kgHcRw9yf g2vuQqzNOUTjy3cKtHTaBN9XMCNKB73mADLQNQk9XIlnrKy5L0USOmagg+R5rmSjSQTu g67aDBe1jGBjlZpBS8ETDvkf1CVzSNcfrtuRWFd2zycUCkXLFAXsrjBSKpwn3gY1Xe/J kmoN5+lhzmsZXJhuZkWJjrDA5xdsLPXqo/v7WTIT3w0CPmc+bkeuV7McHmqSfUlDpWij cO2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc; bh=XhFEgnfA9ZxmDd3zLKeNoNp8dplALMVZBHsfpQz5V0A=; b=aSqGkRLWJ+92uhi3dULMxAuQxsBfMGeIiGaUJZrq5nI34pHJ59zphfl1beT4ApQo9S PhNUMFigXF1lMdJSybWhy8FdHtebJk6UJYW0dvnjVvLSfmshW4lNW0OkfVc7omKY1I5f Ls9vdYSVv9LqZC1YlhTq41tuYLVAJEyKS1ZPeMRKgsL/h6Jq8p+xbhLk0+QFsILMrWEd bHax5S8KPOyx05RtRlcMUzhrwWxWoGiuAWHWnK23Yv3vO3VYpA7g3TytCzl1u/Z9VOHA azxAt5s5F8Rg7JXFDEUJ0a97H4umASaLCrH69VkyNWWT6DSzUHERLj73wEdWHpvtq1Y9 LOPQ== X-Gm-Message-State: AOAM533XHg4vmtcKhUs4yJur6CKVgp6mqg+xitdNpm00A7ZNPnfBQxcv L96dMKzsX1aV7bvMbrx0YQ6ZCGYx4tOokmThP4uDEGfg X-Google-Smtp-Source: ABdhPJzlc/ocLMLQU5xeNBZg6nhHRKiFPTSrvgHZ6t53hfmdM3ph9IX+43Umejdv8OrPcOybEDV5fg/lvs0j/SvC6EI= X-Received: by 2002:a9d:6e19:: with SMTP id e25mr1958231otr.219.1599147606808; Thu, 03 Sep 2020 08:40:06 -0700 (PDT) MIME-Version: 1.0 References: <2868e0ed4e7ebc09b568471c913079516f93fd2fc95e97b0ffea192db1e04275@mahalux.com> In-Reply-To: Date: Thu, 3 Sep 2020 12:39:53 -0300 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000c1ca405ae6a918c" Subject: Re: [PHP-DEV] Pass source object to clone like __clone($origThis) From: david.proweb@gmail.com (David Rodrigues) --0000000000000c1ca405ae6a918c Content-Type: text/plain; charset="UTF-8" Now I rethinked about what I said. Really, maybe clone is not the best option. So maybe we can just use a method that will clone and will have access to both informations. But I don't know if it solves the original message. public function getUserCopy() { $userCopy = clone $this; $this->copies[] = $userCopy; return $userCopy; } Considering it, we have access to both now, with "write to source" support with no additional feature need. Em qui, 3 de set de 2020 11:21, Sara Golemon escreveu: > On Wed, Sep 2, 2020 at 2:11 PM David Rodrigues > wrote: > >> I understand... seems that `$this` is very confusing inside `__clone()`: >> when writing, it writes to the clone, when reading it reads from original. >> >> > That's not an accurate description of what happens today. > > $newObj = clone $oldObj; > // 1. Engine creates a new instance of get_class($oldObj), without calling > the constructor > // 2. Engine copies all properties from the old object to the new object > // 3. Engine invokes $newObj->__clone() > public function __clone() { > // Userspace object handles any property specific re-initialization > required. > // $this always refers to the new object here. > } > > The question Niki asked is appropriate; What would one want to do to > $oldObj here? > If the goal is to read from the old object, then you have that already. > The new object is a perfect copy, so read from that. > If the goal is to write to the old object, then justify why you need to do > so, because it's not a clone operation at that point. > > -Sara > --0000000000000c1ca405ae6a918c--