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 31161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:33:40+00:00 2026-05-10T13:33:40+00:00

What is the purist or correct way to access an object’s properties from within

  • 0

What is the ‘purist’ or ‘correct’ way to access an object’s properties from within an object method that is not a getter/setter method?

I know that from outside of the object you should use a getter/setter, but from within would you just do:

Java:

String property = this.property; 

PHP:

$property = $this->property; 

or would you do:

Java:

String property = this.getProperty(); 

PHP:

$property = $this->getProperty(); 

Forgive me if my Java is a little off, it’s been a year since I programmed in Java…

EDIT:

It seems people are assuming I am talking about private or protected variables/properties only. When I learned OO I was taught to use getters/setters for every single property even if it was public (and actually I was told never to make any variable/property public). So, I may be starting off from a false assumption from the get go. It appears that people answering this question are maybe saying that you should have public properties and that those don’t need getters and setters, which goes against what I was taught, and what I was talking about, although maybe that needs to be discussed as well. That’s probably a good topic for a different question though…

  • 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. 2026-05-10T13:33:41+00:00Added an answer on May 10, 2026 at 1:33 pm

    This has religious war potential, but it seems to me that if you’re using a getter/setter, you should use it internally as well – using both will lead to maintenance problems down the road (e.g. somebody adds code to a setter that needs to run every time that property is set, and the property is being set internally w/o that setter being called).

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

Sidebar

Related Questions

With NaN, it is possible to get a list that will not properly sort:
A SQL VIEW is a global, logical table that may or may not be
Building on from a previous query regarding Class::Struct vs Object::Accessor, I'd like to find
I've just migrated from Access where I would write SQL constantly and quickly using
I have noticed that most PHP-based libraries or frameworks have classes that don't explicitly
I do understand that there's no multiple inheritence in C#. However, I've run into
I have an app that makes a HTTP GET request to a particular URL
Is this the proper way to define an include path for both *nix and
How much work is it reasonable for an object constructor to do? Should it
I'm looking for a strategy for managing links within articles. The body of the

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.