When and why should I use public
, private
, and protected
functions and variables inside a class? 何时以及为何应该在类内使用public
, private
和protected
函数和变量? 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() { // ... }