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

  • Home
  • SEARCH
  • 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 8127823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:39:58+00:00 2026-06-06T07:39:58+00:00

Some of my PHP domain objects have properties which should be set from outside

  • 0

Some of my PHP domain objects have properties which should be set from outside the object, but only by certain client objects. How can I go about enforcing this?

I am using setters within the class, and provided I can find a way to discriminate between different callers, I’m sure I could do some checking in the setter. This seems a bit convoluted though. I get the feeling that I’d be violating an OO design principle (perhaps “tell, don’t ask”?).

I imagine this is a reasonably common scenario. What am I missing?

  • 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-06T07:40:00+00:00Added an answer on June 6, 2026 at 7:40 am

    It strikes me as a bad design in this case. You’d violate the single-responsibility principle of the class. Instead, refactor your code into more than one class, but use composition to attach optional properties.

    For example:

    class MyDataObject {
        private $main_property;
        private $extended_property;
    
        /* ... getters/setters for $main_property. */
        public function set_extended_property(IExtendedProperty $property) {
            $this->extended_property = $property;
        }
    }
    

    Where IExtendedProperty is an interface for the custom property data.

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

Sidebar

Related Questions

I some php code which gets info from a mysql database. The problem is
I have some php files in a server which generate xml code in them.
I need to echo out some specific php code only on the sub-domain of
I have a dynamic URL (http://domain.com/getUsers.php?team=1) that if its manually accessed, returns some Json
I have some PHP code that generates dynamic tables of data on the fly.
So I have some PHP code that looks like: $message = 'Here is the
I have some PHP code that is designed to make a spreadsheet with formulas
I have some PHP code that generates a calendar and then outputs html to
I'm reworking some PHP code to use PDO for the database access, but I'm
I have an ad network script like the following http://cdn.domain.com/ad.php?variables=etc We have about 10,000

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.