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 <poll...@php.net> escreveu: > On Wed, Sep 2, 2020 at 2:11 PM David Rodrigues <david.pro...@gmail.com> > 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 >