why php class clones

bicarel

New Member
I write some code:\[code\]class A { private $x = 1; private $y = "z"; public function setX($x){ $this->x = $x; } public function getX(){ return $this->x; } } $a1 = new A(); $a1->setX(2); echo $a1->getX(); $a2 = $a1; $a2->setX(666); echo $a1->getX();\[/code\]I have output:\[code\]2666\[/code\]But I set value "666" only for object $a2.Why value in $a1 changed too?(OS: Ubuntu 10.04, PHP 5.3.2-1)
 
Back
Top