| Posted by jerrygarciuh on 01/18/08 17:57 
I discovered this by accident today.  How should I get an object'sdata into another variable and make modifications without affecting
 the original object?
 
 // Example of problem
 
 // here is x, a simple object
 class O {}
 $x = new O;
 $x->name = "old";
 $x->sex = "male";
 
 O Object
 (
 [name] => old
 [sex] => male
 )
 // moving x to y
 
 $y = $x;
 
 // modifying y alters x
 
 $y->sex = "female";
 $y->name = "new";
 
 print_r($x);
 
 O Object
 (
 [name] => new
 
 
 [sex] => female
 )
  Navigation: [Reply to this message] |