您:$
:
class ShopCart {
private $maincurrency = USD ;
private function set_Currency() {
$this->$maincurrency = GBP ;
return $this->$maincurrency;
}
}
否则,你会重新创造新的地方功能,然后才使用这一功能。
该手册实际上告诉你:
Within class methods the properties, constants, and methods may be
accessed by using the form $this->property
(where property
is the name
of the property) unless the access is to a static property within the
context of a static class method, in which case it is accessed using
the form self::$property
.
The documentation is your friend; consult it before asking here please.
You may also Hope to consider notreturn
ing any from a setter,beit that s up to You. 这样做是有好处的,即使它并非都包含在PHP中。