note 111041 added to language.oop5.cloning
| From: | nikoolin at ukr dot net | Date: | Tue, 08 Jan 2013 21:33:45 +0000 |
| Subject: | note 111041 added to language.oop5.cloning | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192850@lists.php.net to get a copy of this message | ||
Remark for "Arrays are shallow cloned on assignment, so don't use the clone keyword on
them, just assign it to a new variable. That would lead to an error instead."
Following code works well:
$c = [1,2,3];
$d = [4,5,6];
$a = new StdClass();
$a->arr = $c;
$b = clone $a;
$a->arr = $d;
var_dump($b);
var_dump($a);
Retursn:
object(stdClass)#2 (1) { ["arr"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=>
int(3) } }
object(stdClass)#1 (1) { ["arr"]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=>
int(6) } }
----
Server IP: 69.147.83.199
Probable Submitter: 176.36.151.66
----
Manual Page -- http://php.net/manual/en/language.oop5.cloning.php
Edit -- https://master.php.net/note/edit/111041
Del: integrated -- https://master.php.net/note/delete/111041/integrated
Del: useless -- https://master.php.net/note/delete/111041/useless
Del: bad code -- https://master.php.net/note/delete/111041/bad+code
Del: spam -- https://master.php.net/note/delete/111041/spam
Del: non-english -- https://master.php.net/note/delete/111041/non-english
Del: in docs -- https://master.php.net/note/delete/111041/in+docs
Del: other reasons-- https://master.php.net/note/delete/111041
Reject -- https://master.php.net/note/reject/111041
Search -- https://master.php.net/manage/user-notes.php