The access level of a class member can be
defined by prefixing the declaration with either public, protected, or private. To show their differences let’s define one
field for each access level. The var keyword (deprecated) cannot be used together with
the access modifiers, but using only var gives the same accessibility as public. This is
because public is the default access level for all class members. In our first test we can see that all members
regardless of their visibility are available in the class where they are defined. This
is the only place where the private member can be accessed. A protected member can also be accessed from
inside of a derived class. Finally, public members have unrestricted
access so we can reach them even from outside of the class if we have created an instance.

PHP Tutorial – 12 – Access Levels
Tagged on:                                                                                                                                                             

Leave a Reply

Your email address will not be published. Required fields are marked *