When and why should I use public
, private
, and protected
functions and variables inside a class? What is the difference between them?<
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;