Re: Pass source object to clone like __clone($origThis)

From: Date: Thu, 03 Sep 2020 16:00:39 +0000
Subject: Re: Pass source object to clone like __clone($origThis)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-111827@lists.php.net to get a copy of this message
On Thu, Sep 3, 2020 at 10:40 AM David Rodrigues <david.proweb@gmail.com> 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

« previous php.internals (#111827) next »