You are here: copy of object is a reference in PHP5 « PHP Programming Language « IT news, forums, messages
copy of object is a reference in PHP5

Posted by groups2 on 10/25/07 17:50

Can someone please explain the results below
We switched to PHP 5
if I make a copy of an object, and then change the variable inside the
object the change is reflected in the copy.

Either the copy is a reference to the object or the variable inside
the object is a static variable, I'm not sure what is going on, but It
doesn't seem like it should be doing that. Is that because of a
setting on the server or something ?

<?


$label=new myObj();
$label->settext('the text');

$copy=$label;
print_r($copy);
$label->settext('different text');
print_r($copy);




class myObj{
var $text;
function settext($text){
$this->text=$text;
}

}

?>
results:
myObj Object
(
[text] => the text
)
myObj Object
(
[text] => different text
)

 

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

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