Bug #69677 [NEW]: External attribute specifies a reference to an object, clone the original objec

From: Date: Thu, 21 May 2015 07:10:22 +0000
Subject: Bug #69677 [NEW]: External attribute specifies a reference to an object, clone the original objec
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192797@lists.php.net to get a copy of this message
From: ttlxihuan at 163 dot com Operating system: window,linux PHP version: 5.6.9 Package: Scripting Engine problem Bug Type: Bug Bug description:External attribute specifies a reference to an object, clone the original objec 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" -- Edit bug report at https://bugs.php.net/bug.php?id=69677&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69677&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69677&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69677&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69677&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69677&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69677&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69677&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69677&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69677&r=support Expected behavior: https://bugs.php.net/fix.php?id=69677&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69677&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69677&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69677&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69677&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69677&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69677&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69677&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69677&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69677&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69677&r=mysqlcfg

« previous php.bugs (#192797) next »