class Dog {
protected $bark = 'woof!';
public function __get($key) {
if (isset($this->$key)) {
return $this->$key;
}
}
public function __set($key, $val) {
if (isset($this->$key)) {
$this->$key = $val;
}
}
}
これらの機能を使用するポイントは何ですか。
私が使用できる場合
$dog = new Dog();
$dog->bark = 'woofy';
echo $dog->bark;
なぜ私はわざわざ「樹皮」を宣言するのでしょうprotected
か?この場合の__get()
and__set()
メソッドは、「樹皮」を効果的に公開しますか?