You can set the value of the variable returned by reference, be it a `static` function variable or a `private` property of an object (which is quite dangerous o.o).
Static function variable:
<?php
function &func(){
static $static = 0;
return $static;
}
$var1 =& func();
echo "var1:", $var1, "\n"; func();
$var1 = 90;
echo "var1:", $var1, "\n"; echo "static:", func(), "\n"; ?>
Private property
<?php
class foo {
private $value = 1;
public function &getValue() {
return $this->value;
}
public function setValue($val) {
$this->value = $val;
}
}
$obj = new foo;
$myValue = &$obj->getValue(); echo $obj->getValue(); echo $myValue; $obj->setValue(5);
echo $obj->getValue(); echo $myValue; $myValue = 1000;
echo $obj->getValue(); echo $myValue; ?>