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() { // ... }