Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:16:39+00:00 2026-06-05T07:16:39+00:00

People keep telling me I should be using public, private, or protected access modifiers

  • 0

People keep telling me I should be using public, private, or protected access modifiers in front of all of my class properties and methods. I really don’t understand why. I’m new so bear with me, but the way I see it is this:

  • I am the only one who will work on my code. Not a team.

  • I already know what everything means, plus using an editor that tells me all the declared vars and properties, I know I’m not going to step on my used variables.

One of the explanations I get is that it “protects or hides” your code from people who could see it…..but in PHP there’s no way that I know of for a user to see your code in the first place, who am I hiding it from? If they CAN see my code then they are either a hacker or they are in my account so I can’t stop them anyway.

I can understand if I were working with huge code on a team, but for small things it seems unnecessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:16:41+00:00Added an answer on June 5, 2026 at 7:16 am

    You’re not “hiding” your code from anybody, that’s nonsense.

    What protected and private properties are doing is to tell PHP how you intend to use them. When you create a class, you should usually have an idea of how you want that class to be used. You will have public parts, which other code can interact with, and other parts that you do not want to have other code access directly. Typically you want to restrict the public parts of a class to a very small set of well defined methods which are not going to change. Because once you are using them in other parts of your code, changing them becomes a pain. All the private and protected stuff should only be accessed within the class itself, so changing it around is less of a problem later.

    If you’re the only one working on the code you may say it’s as easy as simply not using the “private parts”. But you are going to make mistakes, and you are going to forget what part belongs where over time. Marking these properties explicitly as protected or private lets PHP help you not violate your own “terms of use”. It’s the difference between a mental note of “don’t touch this” and actually putting a lock on something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

People keep telling me instead of writing shift 1 bit to the left, just
I keep seeing people using doubles in C#. I know I read somewhere that
Here and there people keep talking about memory leaks which occur due unreleased event
I am looking to keep track of people in my iPhone app - either
Someone told me to do this in order to keep track of latest people
EDIT: People keep visiting this post which doesn't have much good information so I'll
I have a html form on my website, but people keep forgetting to fill
People keep giving me examples with carp instead of warn. Why? What makes carp
People keep asking this question and I keep answering it with the same answer
What is a Turing machine and why do people keep mentioning it? My IBM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.