note 72502 added to language.oop5.cloning

From: Date: Mon, 22 Jan 2007 00:30:49 +0000
Subject: note 72502 added to language.oop5.cloning
Groups: php.notes 
Request: Send a blank email to php-notes+get-122020@lists.php.net to get a copy of this message
I ran into the same problem of an array of objects inside of an object that I wanted to clone all pointing to the same objects. However, I agreed that serializing the data was not the answer. It was relatively simple, really: public function __clone() { foreach ($this->varName as &$a) { foreach ($a as &$b) { $b = clone $b; } } } Note, that I was working with a multi-dimensional array and I was not using the Key=>Value pair system, but basically, the point is that if you use foreach, you need to specify that the copied data is to be accessed by reference. ---- Server IP: 69.147.83.197 Probable Submitter: 208.102.101.252 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php Edit -- https://master.php.net/note/edit/72502 Del: integrated -- https://master.php.net/note/delete/72502/integrated Del: useless -- https://master.php.net/note/delete/72502/useless Del: bad code -- https://master.php.net/note/delete/72502/bad+code Del: spam -- https://master.php.net/note/delete/72502/spam Del: non-english -- https://master.php.net/note/delete/72502/non-english Del: in docs -- https://master.php.net/note/delete/72502/in+docs Del: other reasons-- https://master.php.net/note/delete/72502 Reject -- https://master.php.net/note/reject/72502 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122020) next »