What is the difference between public, private, and protected?

后端 未结 17 1604
抹茶落季
抹茶落季 2020-11-21 07:54

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them?<

17条回答
  •  走了就别回头了
    2020-11-21 08:17

    Variables in PHP are cast in three different type:

    Public : values of this variable types are available in all scope and call on execution of you code. declare as: public $examTimeTable;

    Private: Values of this type of variable are only available on only to the class it belongs to. private $classRoomComputers;

    Protected: Values of this class only and only available when Access been granted in a form of inheritance or their child class. generally used :: to grant access by parent class

    protected $familyWealth;

提交回复
热议问题