Best to use Private methods or Protected methods?

后端 未结 10 2328
[愿得一人]
[愿得一人] 2020-12-03 09:52

In a lot of my PHP projects, I end up with classes that have non-public functions that I don\'t intend to extend.

Is it best to declare these as protected, or privat

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 10:17

    I generally avoid private. My reasoning goes that if you have an inheritance relation between two classes, and there are private members, then it is a very strong indicative that you should factor the private parts out into a separate object.

提交回复
热议问题