<?php
class foo {
public $value = 42;
public function &getValue() {
return $this->value;
}
}
$obj = new foo;
$myValue = &$obj->getValue(); // $myValue is a reference to $obj->value, which is 42.
$obj->value = 2;
echo $myValue; // prints the new value of $obj->value, i.e. 2.
?>
<?php
class foo {
public $value = 42;
public function &getValue() {
return $this->value;
}
}
$obj = new foo;
$myValue = $obj->getValue(); // $myValue is a reference to $obj->value, which is 42.
$obj->value = 2;
echo $myValue; // prints the new value of $obj->value, i.e. 2.
Kết qủa: 42
?>
<?phpclassfoo {public $value =42;publicfunctiongetValue() {return$this->value; } } $obj =newfoo; $myValue = $obj->getValue(); // $myValue is a reference to $obj->value, which is 42. $obj->value =2;echo $myValue; // prints the new value of $obj->value, i.e. 2. Kết qủa:42?>