关于php中的__get()和__set()的问题

时间:2011-05-29 20:25:48

标签: 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 = $value;
    }
}

现在我想知道如果我不希望$hello在我到达__get__set函数时隐含地调用我将会做什么,仅针对$world ;

我想要的是在C#中看起来像这样的

   class something {
        public string world;
        public string hello{get;set;}
    }

...谢谢

1 个答案:

答案 0 :(得分:4)

任何无法访问的属性都会自动调用__get__set,因此请将$world设置为private

相关问题