Importance of protected/private in PHP classes

后端 未结 2 760
南笙
南笙 2020-12-21 15:32

Usually when I see PHP classes, most of the variables and functions are either private or protected. Because the PHP is executed on the server side, I don\'t understand why

2条回答
  •  我在风中等你
    2020-12-21 15:53

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

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

提交回复
热议问题