When to use Public, Private, Protected php classes!

When and why should I use and what’s the difference between, publicprivate and protected functions/variables inside a class?

You use:

  • public scope to make that variable/function available from anywhere, other classes and instances of the object.
  • private scope when you want your variable/function to be visible in its own class only.
  • protected scope when you want to make your variable/function visible in all classes that extend current class including the parent class.

More: (For comprehensive information)

Share if you like...Share on FacebookTweet about this on TwitterShare on Google+Pin on PinterestShare on TumblrEmail this to someone

Leave a Reply