Bug #79291 [Opn->Nab]: Clone provokes a recursive reference

From: Date: Thu, 20 Feb 2020 12:57:26 +0000
Subject: Bug #79291 [Opn->Nab]: Clone provokes a recursive reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225652@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79291&edit=1 ID: 79291 Updated by: nikic@php.net Reported by: ihorshein at gmail dot com Summary: Clone provokes a recursive reference -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: All PHP Version: 7.2.28 Block user comment: N Private report: N New Comment: The first example creates the reference before performing the clone, the second one creates the reference after the clone. If the clone is created afterwards, the reference is also preserved. Thus the difference in behavior. Previous Comments: ------------------------------------------------------------------------ [2020-02-20 12:47:11] ihorshein at gmail dot com Description: ------------ - The result of clone passed as an argument provokes a recursive reference. + The result of clone stored in the variable that is passed as an argument does not cause problems. Test script: --------------- function assign(&$r, $c){ $r = $c; } class A{ private $c; public function run(){ assign($this->c, clone $this); // this code generates actual result //$c = clone $this; //assign($this->c, $c); this code generates the expected result } } $o = new A(); $o->run(); var_dump($o); Expected result: ---------------- object(A)#27 (1) { ["c":"A":private]=> object(A)#13 (1) { ["c":"A":private]=> NULL } } Actual result: -------------- object(A)#21 (1) { ["c":"A":private]=> &object(A)#20 (1) { ["c":"A":private]=> *RECURSION* } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79291&edit=1

« previous php.bugs (#225652) next »