Please watch the piece of code below.... I have $z as reference to $y, I change the value of $y but the value of $z is still the old one and not changed... I'm really confused, can some body help?
<?php
class foo {
private $list;
function __construct()
{
for($i = 0; $i < 4; $i++)
$this->list[$i] = $i;
}
public function &GetArray()
{
return($this->list);
}
}
$x = new foo();
$y = &$x->GetArray();
$z = $y; // now $z is also a reference to $list, or?
$y[2] = 9; // Here I change element 3's value
print_r($y); // this prints: Array ( [0] => 0 [1] => 1 [2] => 9 [3] => 3 )
print_r($z); // here is the surprizing, it does not print the same output as $y but
// it prints: Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 )
?>Thank you
Mizhad