note 106135 deleted from language.oop5.cloning by cmb

From: Date: Sun, 10 Jul 2016 20:20:48 +0000
Subject: note 106135 deleted from language.oop5.cloning by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205959@lists.php.net to get a copy of this message
Note Submitter: walkman at walkman dot pk ---- 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.

« previous php.notes (#205959) next »