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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:43:41+00:00 2026-06-03T11:43:41+00:00

I just realize I’ve been doing that and it seems like the objects’ properties

  • 0

I just realize I’ve been doing that and it seems like the objects’ properties are still being set when I use

object->set($property, $value);

What is the expected behavior in this situation?

  • 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-03T11:43:48+00:00Added an answer on June 3, 2026 at 11:43 am
    object->set($property, $value);
    

    set is just an method of the object’s object here, probably you are referring to setter method. which takes two arguments and pass it to the class property. the behavior of setting the class depends on the code of set method, there are some benefits of using this method.

    there are two ways for storing the data in a class, one way is to directly assign the values to class property for example

    class Foo {
        public $a;
        public $b;
    }
    

    if you need to assign the values to the class property you would do like.

    $object = new Foo();
    $object->a = 'hello';
    $object->b = 'world';
    

    now the class property $a will contain the value hello and the class property $b will contain the value world, however there is a problem to this approach, we can never tell the user what type of data should come in. if we need to store only integers in $a there is no way we can do that. to overcome this you can use a setter meth, wherein we declare the class property as protected or private, and set the value through a class method.

    class Foo {
        protected $a;
        protected $b;
    
       public function set($a) {
           //you can validate the data here before assigning.
           $this->a = $a;
       }
    }
    

    you can simply google about getter and setter method and get more information.

    Class Constructor
    

    class constructor is nothing but an method which is invoked automatically when you instantiate an object. consider that you want to instantiate an object by forcing the user to provide the user id first. or may be you want to do some useful calculation before other methods are called. this is where class constructor comes into picture. consider the below example

    class Bar {
    
        protected $userId;    
    
        public function __construct($userId) {
            $this->userId = $userId;
            //any more code execution that needs to be done while instantiating the class can be placed here
        }
    }
    

    so when you instantiate the object

    $object = new Bar();
    

    this will result into error. since you haven’t provided the userId. so the correct way is.

    $object = new Bar(1);
    

    now the class property $userId will hold the value one upon the instantiation of the object.

    hope this helps you.

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

Sidebar

Related Questions

I just realize that in my forms I couldn't save name like O'Brian (It
I'm doing custom-rolled view tracking on my website, and I just realize that I
Now, I realize that this question has been answered before, but I just can't
I just realized that in different Activities, I use different SharedPreferences. For example, I
I just realize that maybe I was mistaken all the time in exposing T[]
I realize that Unity is a game engine and XNA is just a framework,
While I realize that I could just show the form off-screen and hide it,
I realize that this topic have been brought up sometimes, but I find myself
I just came to realize that my project is currently using methods that are
I realize this seems like an obvious JS type thing - but I'm new

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.