Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111827 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25182 invoked from network); 3 Sep 2020 16:55:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 16:55:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1174A180554 for ; Thu, 3 Sep 2020 09:00:52 -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-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 09:00:51 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id y4so4342115ljk.8 for ; Thu, 03 Sep 2020 09:00:51 -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=O0AuctWSMcoghq/2Yj0E7CNKnU4lqyZSEIXTvRkDuQs=; b=DMilw1dIvoIOp9EheTH9YHEO1FS0/i6YfY1e6G3BOdMlB/PnQkLIJuf0BLxwUc6Gqw 8iG360DqxB6JulBn0puox/BRykXW265W9vyB3syXft8tsPiIH32552ZMlZa+Kckx4hpB bjwA+2fcIjfXoiE2/OnrCOlqyPZAY9K5pGcHkUUcIVAe2iLGyr2qRF+AQsHdLaw1urwf 0WTFhzqRJA2x/Wou4b1yDE02Emvv2rIIZ6fJa36nt4qY952jOtrdJdXnXlhLhhTBF7em x15iuS6ugiDNYPXKffZt43Lxyn2RwmfDSXfcY3WKECV1weZCiEwkJ7yyAzAnHaK/SKOW DnAg== X-Gm-Message-State: AOAM530TaVrDLBjzvoaW9EqxPUVjdas9VrILnqKhGIMaocNcKeYxmCYn RUo42isjwi16y1CSTDV6uXvOfBJLjjIqmHrsdRVNbw== X-Google-Smtp-Source: ABdhPJzpI1DQPURr86n2Z979Ec3u5jhkBr/kPOG2rhrPR42KmwOEhTCqpe9CRmZlS+GXWObI72l2tusUPcPWFB1mJ+g= X-Received: by 2002:a05:651c:504:: with SMTP id o4mr1548301ljp.58.1599148850001; Thu, 03 Sep 2020 09:00:50 -0700 (PDT) MIME-Version: 1.0 References: <2868e0ed4e7ebc09b568471c913079516f93fd2fc95e97b0ffea192db1e04275@mahalux.com> In-Reply-To: Date: Thu, 3 Sep 2020 11:00:39 -0500 Message-ID: To: David Rodrigues Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000025d64b05ae6adb77" Subject: Re: [PHP-DEV] Pass source object to clone like __clone($origThis) From: pollita@php.net (Sara Golemon) --00000000000025d64b05ae6adb77 Content-Type: text/plain; charset="UTF-8" On Thu, Sep 3, 2020 at 10:40 AM David Rodrigues wrote: > 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; > } > > If your goal is to track copies, then a static makes much more sense. class AllKnowing { private static $copies = []; public function __construct(...) { self::$copies[] = $this; .... } public function __clone() { self::$copies[] = $this; } } -Sara --00000000000025d64b05ae6adb77--