I discovered this by accident today. How should I get an object's
data 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
)
data 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
)
Comment