吸气剂和吸气剂? - Getter and Setter?

10/14 07:53
阅读数 0

问题:

I'm not a PHP developer, so I'm wondering if in PHP is more popular to use explicit getter/setters, in a pure OOP style, with private fields (the way I like):我不是 PHP 开发人员,所以我想知道在 PHP 中是否更流行使用显式 getter/setter,以纯 OOP 风格,带有私有字段(我喜欢的方式):

class MyClass {
    private $firstField;
    private $secondField;

    public function getFirstField() {
        return $this->firstField;
    }
    public function setFirstField($x) {
        $this->firstField = $x;
    }
    public function getSecondField() {
        return $this->secondField;
    }
    public function setSecondField($x) {
        $this->secondField = $x;
    }
}

or just public fields:或只是公共领域:

class MyClass {
    public $firstField;
    public $secondField;
}

Thanks谢谢


解决方案:

参考一: https://en.stackoom.com/question/In6T
参考二: https://stackoom.com/question/In6T
展开阅读全文
php
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部