note 97348 added to language.oop5.cloning

From: Date: Thu, 15 Apr 2010 12:41:08 +0000
Subject: note 97348 added to language.oop5.cloning
Groups: php.notes 
Request: Send a blank email to php-notes+get-168265@lists.php.net to get a copy of this message
For me it wasn't very clear to how this cloning of objects really worked so I made this little bit of code: <?php class foo { public $test; public function test() { echo 'give us a '.$this->test."<br>\n"; } } class bar { public $foo; public function insertFoo($foo) { $this->foo = $foo; } } $foo = new foo(); $foo->test = 'foo'; $bar = new bar(); $bar->insertFoo($foo); $foo->test(); $bar->foo->test(); $foo->test = 'bar'; $foo->test(); $bar->foo->test(); $bar->foo = clone $foo; $bar->foo->test = 'woop woop'; $foo->test(); $bar->foo->test(); // result: // give us a foo // give us a foo // give us a bar // give us a bar // give us a bar // give us a woop woop ?> ---- Server IP: 69.147.83.197 Probable Submitter: 195.35.136.2 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php Edit -- https://master.php.net/note/edit/97348 Del: integrated -- https://master.php.net/note/delete/97348/integrated Del: useless -- https://master.php.net/note/delete/97348/useless Del: bad code -- https://master.php.net/note/delete/97348/bad+code Del: spam -- https://master.php.net/note/delete/97348/spam Del: non-english -- https://master.php.net/note/delete/97348/non-english Del: in docs -- https://master.php.net/note/delete/97348/in+docs Del: other reasons-- https://master.php.net/note/delete/97348 Reject -- https://master.php.net/note/reject/97348 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168265) next »