Re: Pass source object to clone like __clone($origThis)
| From: | David Rodrigues | Date: | Thu, 03 Sep 2020 16:03:29 +0000 |
| Subject: | Re: Pass source object to clone like __clone($origThis) | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111828@lists.php.net to get a copy of this message | ||
It was just an example to avoid modify how clone works, using existing
features. :)
Em qui, 3 de set de 2020 13:00, Sara Golemon <pollita@php.net> escreveu:
> 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
>