|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-05-24 22:21 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2015-05-24 22:21 UTC] cmb@php.net
[2015-05-25 03:40 UTC] ttlxihuan at 163 dot com
[2015-05-26 10:22 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 11:00:02 2026 UTC |
Description: ------------ class a{ public $n; public function __construct($n) { $this->n=$n; $N=&$this->n; } } class b{ public $n; public function __construct($n) { $this->n=$n; } } class c{ public function t($b){ $cb= clone $b; $cb->n='clone'; var_dump($cb->n,$b->n); } } Test script: --------------- $c=new c(); $a=new a('new'); $b=new b('new'); $n=&$b->n; //Class A specified reference when constructing, clone and modify the properties of the original object has no effect $c->t($a); //Class B specified external references, clone modify properties directly affect the original object properties $c->t($b); Expected result: ---------------- I may be wrong envisioned, I believe that adding a reference to the cloned object should be completely independent and does not affect the original object property values.The end result should be: string(5) "clone" string(3) "new" string(5) "clone" string(5) "new" Actual result: -------------- #Result: string(5) "clone" string(3) "new" string(5) "clone" string(5) "clone"