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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:05:50+00:00 2026-06-10T09:05:50+00:00

I have a set of classes which hold state for the database. It’s like

  • 0

I have a set of classes which hold state for the database. It’s like a micro-ORM pattern. So for this solution I load in the structure of a few tables as dynamic properties to the class so that the class looks something like:

  • Object
    • [tbl_name]
      • attribute1
      • attribute2
      • attribute3
    • [tbl_name]
      • attribute1
      • attribute2
      • attribute3

All of the attributes are public properties because I set them with something like this:

$object->{$table_name}->{$attribute} = 'foobar';

What I’d like though is for these dynamically set properties to be private. Why? Well because, and please don’t miss the irony here, I want to make them public again through an overloaded getter/setter using __get() and __set(). Again we come back to the question of why. Well actually for “getting” I would have been fine with a public property but for setting I want to apply some logic before allowing the setting. Here’s my simplified __set() function which gives you an idea of what I’m trying to achieve:

public function __set ( $property , $value ) {

    if ( !in_array ($property , $blocked_properties) ) {
        $this->property = $value;
        $this->trigger_event ( $property );
    }
}

Make sense? I’m happy to solve this problem other ways but this seems like a very graceful way to do this if only I could dynamically set private instance variables.

  • 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-10T09:05:51+00:00Added an answer on June 10, 2026 at 9:05 am

    Don’t make those actual properties, store them in a private array and access them only through magic methods:

    class ORM {
    
        private $fields = array();
    
        public function __get($name) {
            return $this->fields[$name];
        }
    
        public function __set($name, $value) {
            $this->fields[$name] = $value;
        }
    
    }
    

    It behaves exactly how you want it.

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

Sidebar

Related Questions

I have classes which have automatic properties only like public customerName {get; set;}. They
I have a set of classes which hold only data (no operations have been
I have a set of classes like this: class A { public: int DoIt()
I've got quite a number of classes, which have got the standard set and
I have a set of classes which extend an abstract class. The abstract class
I have a set of classes which are all derived from a common base
I have a set of classes which I didn't write, and they're read only.
I have set of classes which inherit from a single super class: Super |
Here's a set of C++ classes which implement a kind of adapter pattern: #include
I have a set of related C++ classes which must be wrapped and exported

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.