0

I recently started coding in PHP OOP, and i really like it. I have on question though. Does it matter what scope i use for my methods and properties.

I get that:

  • Public scope means the property or method can be accessed from everywhere.
  • Private scope means the property or method can be accessed from inside the class.
  • Protected means the property or method can be accessed from the class and extended classes, not quite sure about that one.

But right now i'm only using public scope, for all methods and properties. Should i for example use private if i know the method or property should never be accessed from outside the class?

And is there some kind of advantage gained from using the proper scope that fits the method or properties use.

1 Answers1

0

Short answer: Yes, you should use them.

For the long answer, I suggest you to read this SO post: https://stackoverflow.com/a/21902271/2855530

Community
  • 1
  • 1
Stanimir Dimitrov
  • 1,872
  • 2
  • 20
  • 25