You are here: Copying an Object passes Object by Reference?! « PHP Programming Language « IT news, forums, messages
Copying an Object passes Object by Reference?!

Posted by jerrygarciuh on 01/18/08 17:57

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
)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация