The Importance of Protected / Private in PHP Classes

Usually, when I see PHP classes, most variables and functions are private or protected. Since PHP runs on the server side, I don’t understand why you need these security features. Are they available for security or am I missing something?

+2
oop php
Jan 27 '10 at 11:04 on
source share
2 answers

Private and protected meaning in the context of visibility , not stricto senso security features.

Class members declared public can be accessed everywhere. Participants declared protected can only be accessed within the class itself and the inherited and parent classes. Participants declared can only be accessed by the class that defines the member.

+3
Jan 27 '10 at 11:07
source share

This is not about security, but about the design of OOP. They tell you and other developers how to use the class. Private and protected variables are intended for internal use, while public members are intended for public use.

+2
Jan 27 '10 at 11:08
source share



All Articles