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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:17:07+00:00 2026-06-12T11:17:07+00:00

I have a event class that i am using to insert/update data into my

  • 0

I have a event class that i am using to insert/update data into my database. Is there a way that i can create the public variables from my db_fields array so that i am not having to duplicate the data?

This is my current structure which works…

class event{
    protected static $table_name='tName';
    protected static $db_fields = array('field1','field2','field3','field4','field5');

    public $field1;
    public $field2;
    public $field3;
    public $field4;
    public $field5;
}

I would like to have something like this..

class event{
    protected static $table_name='tName';
    protected static $db_fields = array('field1','field2','field3','field4','field5');

    function __construct() {
        create_public_vars_here($db_fields);
    }

}

Thanks!

  • 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-12T11:17:08+00:00Added an answer on June 12, 2026 at 11:17 am

    You can try the following:

    class event{
    
        protected static $table_name='tName';
        protected static $db_fields = array('field1','field2','field3','field4','field5');
    
        function __construct() {
            foreach (self::$db_fields as $var) {
                $this->$var = $whateverDefaultValue;
            }
            // After the foreach loop, you'll have a bunch of properties of this object with the variable names being the string values of the $db_fiels.
            // For example, you'll have $field1, $field2, etc and they will be loaded with the value $whateverDefaultValue (probably want to set it to null).
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that raises an event with an error message. In some
I have a class that contains this class method: def self.get_event_record(row, participant) event =
I have a backend class that has to raise an event with no arguments.
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have an Event class. Due to the way dates are handled, we need
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
Let's say I have defined the following class: public abstract class Event { public
I have built a function using jQuery to insert into a table a new
I have a basic Window class that I need to have events such as
I have following event class. I have a question related to the Property method

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.