echo 'test';
class createdclass {
public $name;
}
class testc {
function &testm(){
$myvar =& new createdclass();
return $myvar;
}
}
$testo = new testc();
$a =& $testo->testm();
$a->name = 'Douglas';
$b =& $testo->testm();
$b->name = 'Scott';
echo $a->name;
echo $b->name;
myvar is a reference to an object
a and b are references to the same object
I changed a, then I changed b, but a wasn’t changed by b
Why?
In your code each call to
testm()creates a new instance of createdclass. So $a and $b aren’t the same object.