Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111833 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39590 invoked from network); 3 Sep 2020 18:38:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 18:38:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DAC60180511 for ; Thu, 3 Sep 2020 10:43:59 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 10:43:59 -0700 (PDT) Received: by mail-ot1-f43.google.com with SMTP id v16so3465364otp.10 for ; Thu, 03 Sep 2020 10:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=m6bKusszbUQuE7SLjUvvzYXTPjTZlTN1Hq8n3UwVgqY=; b=BjguGmH1bprZCrbUqnSnKPUDjZOMhbWDJ9qyNTOc3+rhxWirwXu5r/lmgFCWcc5RyW FB7SOAEJxkTTnifubqaVA8S8PsUX4I2Bn7Kq6Wz6eO7bdgv5imKVEuJrJADzHmU2Fq7e je0cN3K7jAUtaE1IMjzm+FC7T6+ahHwxYZTfN1EYOMDWWmd1E3+3oo4CUFUwB+tCWnLU yltgjLihrFCnappL7kC0bwMsmW6jGD8xHVANF/1e7H6coiQGobR89kA/b+77v48os37p Qo1EVtxn3GqXkEZBSUqdgbdetHafhYCbocD03qavHIBI7DL7pqXTvW9nmawbR/WPWP34 CBVA== 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:cc; bh=m6bKusszbUQuE7SLjUvvzYXTPjTZlTN1Hq8n3UwVgqY=; b=lT7dfeERWwF+HYo4kkAORZeU9oLx17ZKt0E7umAo+TDiP3zObZ5e2suLUUUb0wR1RF 74oyMBnX3RVewDq4KMhkufaJbK9aTogrtDSxckNtEuIdnsOqqHqz+/Vaut7Mx3sorEsn fJaH/VfP03tSoaH8c6qaxak4fCgNf5Qec5xy2cT6LMedJpxO6PuaZVyyRL1jUFBhQI1X C9nxvfDoeCcwSgDU+bW7YIK4TIYES9MBJm0nOYFGadhKp6oJbt1jDzZGk1/kX8YUBVei jjDuzcM01C85o00IW3e39GMYFqti5mRL3a0qDamKWp/b7AA0YSoNnQs3GV7SBxz75c04 BT8A== X-Gm-Message-State: AOAM532vRgDpYyXjbZkYRmrqZ9TufDcb86WOXDVxNjZ8+KKx0I0gnCoC 5Xw9Aj6gHNyfK0gfTOuVqL24mZbPpwpmEP7nvzFy76XQ X-Google-Smtp-Source: ABdhPJzMJMEbFZ335DRtEfsYd2WLT4Gif0zs6ri+sHLkAa6OoKpCNatPji1fsxNYC9Ul3FGKlnTmO36WI2hbNvV0QzM= X-Received: by 2002:a9d:7745:: with SMTP id t5mr2457423otl.114.1599155037579; Thu, 03 Sep 2020 10:43:57 -0700 (PDT) MIME-Version: 1.0 References: <2868e0ed4e7ebc09b568471c913079516f93fd2fc95e97b0ffea192db1e04275@mahalux.com> <338f74ebb60ebac19ec4316f2e64d720988c60df9ac9e116a5ab364974fea8fe@mahalux.com> In-Reply-To: <338f74ebb60ebac19ec4316f2e64d720988c60df9ac9e116a5ab364974fea8fe@mahalux.com> Date: Thu, 3 Sep 2020 14:43:43 -0300 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000f4aeb305ae6c4bb7" Subject: Re: [PHP-DEV] Pass source object to clone like __clone($origThis) From: david.proweb@gmail.com (David Rodrigues) --000000000000f4aeb305ae6c4bb7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Just to I know, it can't be done by an intermediary method like my previous example? Why are the limitations to that? About PR, could you provide some additional tests? Thanks! Em qui, 3 de set de 2020 13:37, Michael Vo=C5=99=C3=AD=C5=A1ek - =C4=8CVUT = FEL < vorismi3@fel.cvut.cz> escreveu: > The goal is to be able to access the original object and it's id/hash. > > Usecases: > > - something is associated with the object using the object id/hash and > it needs to be cloned as well > > we need the original object to obtain it's id/hash for spl_object_id and > spl_object_hash methods > > - bounded Closures ar associated with the original object and they needs > to be rebound to the cloned object > > example: > > public function __clone(self $origThis) > { > if ((new \ReflectionFunction($this->fx))->getClosureThis() =3D=3D=3D > $origThis) { > $this->fx =3D \Closure::bind($this->fx, $this); > } > } > > Modification of php is simple: > > > https://github.com/php/php-src/pull/6063/files#diff-beea8c5a8ceb318220b34= b73e4ecfc98R252 > > > we simply pass the old object as 1 parameter. I belive, passing old > object have positives and no performance nor compatibility impact. All > other current solutions require an extra property and a lot of code, as > assigning in constructor is not enough (due serialization etc.), or it > is even impossible, if object was created using reflection without > constructor. > > With kind regards / Mit freundlichen Gr=C3=BC=C3=9Fen / S p=C5=99=C3=A1te= lsk=C3=BDm pozdravem, > > Michael Vo=C5=99=C3=AD=C5=A1ek > > On 3 Sep 2020 18:00, Sara Golemon wrote: > > > 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 hav= e > >> access to both informations. But I don't know if it solves the origina= l > >> message. > >> > >> public function getUserCopy() { > >> $userCopy =3D clone $this; > >> $this->copies[] =3D $userCopy; > >> > >> return $userCopy; > >> } > > If your goal is to track copies, then a static makes much more sense. > > > > class AllKnowing { > > private static $copies =3D []; > > > > public function __construct(...) { > > self::$copies[] =3D $this; > > .... > > } > > > > public function __clone() { > > self::$copies[] =3D $this; > > } > > } > > > > -Sara --000000000000f4aeb305ae6c4bb7--