note 106135 added to language.oop5.cloning

From: Date: Thu, 13 Oct 2011 12:11:57 +0000
Subject: note 106135 added to language.oop5.cloning
Groups: php.notes 
Request: Send a blank email to php-notes+get-183847@lists.php.net to get a copy of this message
If you want a property that gets the same value in every clone if changed, you can do this simple trick: <?php class A { public $name ; public function __construct() { $this->name = & $this->name; } } $a = new A; $a->name = "George"; $b = clone $a; $b->name = "Somebody else"; var_dump($a); var_dump($b); ?> this will output: object(A)#1 (1) { ["name"]=> &string(13) "Somebody else" } object(A)#2 (1) { ["name"]=> &string(13) "Somebody else" } You can change any of the clones property and all of the others will change accordingly. ---- Server IP: 92.43.200.200 Probable Submitter: 87.97.108.247 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php Edit -- https://master.php.net/note/edit/106135 Del: integrated -- https://master.php.net/note/delete/106135/integrated Del: useless -- https://master.php.net/note/delete/106135/useless Del: bad code -- https://master.php.net/note/delete/106135/bad+code Del: spam -- https://master.php.net/note/delete/106135/spam Del: non-english -- https://master.php.net/note/delete/106135/non-english Del: in docs -- https://master.php.net/note/delete/106135/in+docs Del: other reasons-- https://master.php.net/note/delete/106135 Reject -- https://master.php.net/note/reject/106135 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183847) next »