公共,私有和受保护的有什么区别? - What is the difference between public, private, and protected?

问题:

When and why should I use public , private , and protected functions and variables inside a class? 何时以及为何应该在类内使用publicprivateprotected函数和变量? What is the difference between them? 它们之间有什么区别? ide

Examples: 例子: 函数

// Public
public $variable;
public function doSomething() {
  // ...
}

// Private
private $variable;
private function doSomething() {
  // ...
}

// Protected
protected $variable;
protected function doSomething() {
  // ...
}

解决方案:

参考一: https://stackoom.com/question/IIdd/公共-私有和受保护的有什么区别
参考二: https://oldbug.net/q/IIdd/What-is-the-difference-between-public-private-and-protected
相关文章
相关标签/搜索