Importance of protected/private in PHP classes

后端 未结 2 675
南笙
南笙 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:52

    It's not really about security, but more about the OOP design. They tell you, and other developers, how the class should be used. Private and protected variables are for internal use, while public members are for public use.

提交回复
热议问题