Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111818 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4696 invoked from network); 3 Sep 2020 15:16:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 15:16:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9AFC21804E3 for ; Thu, 3 Sep 2020 07:21:21 -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.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 07:21:21 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id s205so3940067lja.7 for ; Thu, 03 Sep 2020 07:21:21 -0700 (PDT) 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:to:cc; bh=xWzJIX3jUsLtkddhSz8EHHzYJWUuq9F91XCZmn1iftM=; b=WDG6bRpNZAaoR5GZJIt5uvs59jqLm2DHuLWVmPOy7JtO4lHMZ9yias0gyxeOWCmi9I WPZ73VcOc8Tv/5hYPNuHAZR3gD0muaGBTEUtfrogaongpdiQi+JFV1oI78N0bMsdXqP4 6LcZp7u+/n9zSijpvCg/WVE3e5yoLsIfMgAb/3Oz9Jo8rxBWefOJ3cSbf4+uxucuteng 3FIQnSBz8/v+Dok+BJHvO06JiUBCY/UGx3d+8i5QdvQ2I3Ziimv3aDAB9+uRjanDBzym 7BJqhT1uaffXBZnzTAL0OwTTGmB5ngev2SwUgp3MOyhNQCAIEiUSxWfBES711QrdJ79n LQaQ== X-Gm-Message-State: AOAM533dHwiwOJKWxs2rNVJ+aHHen0C3x87VLTbm3NgjJS48P13bjbBC DaldKwkksakfpEGMxIEyG4/FJLBBek8NEg9YnO1Y+A== X-Google-Smtp-Source: ABdhPJwbupnxECbonc9du0tEpQcsarmBmNG+fsfuVYehVX8Z2f5VjRfjyiwpMyIfA1HGWJkcFr2N9DxLo88EAm4HMws= X-Received: by 2002:a2e:8150:: with SMTP id t16mr1409488ljg.160.1599142879322; Thu, 03 Sep 2020 07:21:19 -0700 (PDT) MIME-Version: 1.0 References: <2868e0ed4e7ebc09b568471c913079516f93fd2fc95e97b0ffea192db1e04275@mahalux.com> In-Reply-To: Date: Thu, 3 Sep 2020 09:21:08 -0500 Message-ID: To: David Rodrigues Cc: =?UTF-8?B?TWljaGFlbCBWb8WZw63FoWVrIC0gxIxWVVQgRkVM?= , PHP internals Content-Type: multipart/alternative; boundary="0000000000004478a905ae697757" Subject: Re: [PHP-DEV] Pass source object to clone like __clone($origThis) From: pollita@php.net (Sara Golemon) --0000000000004478a905ae697757 Content-Type: text/plain; charset="UTF-8" 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 --0000000000004478a905ae697757--