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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:58:36+00:00 2026-06-02T00:58:36+00:00

This is a stupid question, but i want to know, how is named the

  • 0

This is a stupid question, but i want to know, how is named the OOP functionnality that consists to give a value to an object and dont lost the object, for example in javascript it works with the String object, but if i want to create an Object which i can set a value, how i do that ? :

// i set beer to budweiser
beer = new String('budweiser');

// beer is still String object and i changed its value ..
beer = 'Pabst';

But in PHP when i do something like :

//robert is a new guy instance, and he is cool
$robert = new Guy('cool');

//but you discover he is stealing ur money
$robert = 'asshole';

//now if i want to use a Guy method, i cant
$robert->throwRocks();

so i want to know, how this OOP functionality is named and how i can use it in PHP and JS ?

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-02T00:58:38+00:00Added an answer on June 2, 2026 at 12:58 am

    Im not sure I understand your question (nor the humour), but you can make a class and assign variables to that class through the construct & __set then retrieve them through a method or property:

    Here is some pseudo code:

    <?php 
    Class guy{
        private $vars = array();
    
        //Assigns name from the passed param
        function __construct($name){
            $this->name = $name;
        }
    
        public function __set($index, $value){$this->vars[$index] = $value;}
        public function __get($index){return $this->vars[$index];}
    
        public function getName(){
        return $this->name;
        }
    }
    
    $guy = new guy('Bob');
    
    echo $guy->getName(); //Bob
    
    $guy->name = "Steve";
    
    echo $guy->getName(); //Steve
    
    $guy->somerandVar = 'Bill'; //(Can only set because of the __set setter)
    
    echo $guy->somerandVar; //Bill //Can only get because of the __get getter
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is maybe a stupid question, but I want to know if my code
I know this may be a stupid question to ask but I want to
This maybe a stupid question, but I want to know if I can copy
This might be a stupid question but I'm new at all this. I want
i know this is a stupid question but i d'ont know how to do
This might be a stupid question, but I notice that in a good number
I know this is very stupid question, but I wanted to clarify this. Let's
i'm afraid that this is a stupid question, but i must assume that i
i know this question may sound stupid to you guys, but i am a
I don't know if this is a stupid question, but is there any way

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.