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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:21:34+00:00 2026-05-22T17:21:34+00:00

Hey guys. I was designing a model for some data, and wanted it to

  • 0

Hey guys. I was designing a model for some data, and wanted it to work like: $this->groupmodel->VARIABLE->FUNCTION(VAR1, VAR2); to call a function, where VARIABLE is changeable to anything, and passed to the function.

This feels more correct (then say $this->groupmodel->FUNCTION(VARIABLE, VAR1, VAR2)), because each VARIABLE has the exact same functions, and the functions are being preformed (technically) on VARIABLE. Is this possible?
Note that VARIABLE can be set anywhere (in its own function or in the function being called) (it is persistent throughout the class, but needs to be set each call).

Max

  • 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-05-22T17:21:34+00:00Added an answer on May 22, 2026 at 5:21 pm

    You should create a class implementing the functions you want to use, and all your “variables” should be objects of that class. For instance:

    class Kid {
        private $age = 0;
        public function _construct($age){
          $this->age = $age;
        }
        public function birthday() { // implement in Kid instead of in Groupmodel
          $this->age++;
          echo "Growing old... ";
        }
        public function age($age_new = null){  // age setter and getter
          if(!is_null($age_new)){
            $this->age = $age_new;
          }
          return $this->age;
        }
    }
    

    And then inside your groupmodel:

    class GroupModel {
    
      private $variables;
    
      public function _set($name, $value) {
        if (array_key_exists($name, $this->variables)) {
          $this->variables[$name]->age($value);
        } else {
          $this->variables[$name] = new Kid($value);
        }
      }
    
      public function _get($name) {
        if (array_key_exists($name, $this->variables)) {
          return $this->variables[$name];
        } else {
          return null;
        }
      }
    }
    

    so you can call:

    $this->groupmodel = new GroupModel()
    $this->groupmodel->var1 = 8
    $this->groupmodel->var1->birthday();  // will add 1 to var1's age and print "Growing old"
    $this->groupmodel->var1 = 9  // will replace var1's age
    

    What we are doing here is creating objects of class Kid automatically every time you try to set a property of the GroupModel object. (This is what the magic method _set() does)

    In fact it creates them as elements of a private array instead of real properties of GroupModel.

    Then, when trying to access those “properties”, _get() will be invoked and it will retrieve the element of the array and return it.

    As it will be an object of class Kid, you could call every method it implements (like birthday()).

    For more information on Overloading and magic methods like _get and _set, see:

    http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members

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

Sidebar

Related Questions

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey guys I'm getting a syntax error on my CONCATS for some reason, this
Hey guys, I want to store a categorized list of URLs. This is an
Hey Guys, here is my code for this, the only help i get from
Hey guys, I'm writing a word wrap function to format console text in C++.
Hey guys i am trying to automate my system at work for sending artwork
Hey guys i'm making a website but for some reason my div tags are
Hey guys..I am designing a set-up wizard using CPropertySheet and CpropertyPage in MFC application...I
Hey guys, I want to make a function loop over all elements that have
Hey guys, I'm currently trying to implement a function using C that takes in

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.