关于php中的_get()和_set()的问题
据我所知,在php中定义_get和_set函数时,获取属性的方式不会改变。我是说关于php中的_get()和_set()的问题,php,class,Php,Class,据我所知,在php中定义_get和_set函数时,获取属性的方式不会改变。我是说 class something { public $world; public $hello; public function __get($name) { return $this - > $name; } public function _set($name, $value) { $this - > $name = $va
class something {
public $world;
public $hello;
public function __get($name) {
return $this - > $name;
}
public function _set($name, $value) {
$this - > $name = $value;
}
}
现在我想知道如果我不想$hello
调用\uuuu get
和\uu set
函数,当我到达它时,我该怎么办,只为$world
我想要的是C中的这个#
感谢……任何不可访问的属性都将自动调用
\uuu get
和\uu set
,因此,将$world
设置为private
任何不可访问的属性都将自动调用\uu get
和\uu set
,因此,将$world
设置为private
那么你的意思是你不想要$something->\u设置('hello')那么你的意思是你不想要$something->\u设置('hello')不可访问或可访问?我的意思是说,$a=newsomething();echo$a->$hello
我不想让$hello
呼叫\uu get
和\uu set
。你还没试过吗<由于$hello
是一个已定义的公共属性,因此不会调用code>\uu get/\uu set
。不可接近还是可接近?我的意思是说,$a=newsomething();echo$a->$hello
我不想让$hello
呼叫\uu get
和\uu set
。你还没试过吗<由于$hello
是一个已定义的公共属性,因此不会调用code>\uu get/\uu set
。
class something {
public string world;
public string hello{get;set;}
}