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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:09:18+00:00 2026-06-13T04:09:18+00:00

First, sorry for the stupid question, but I was reading an article in php.net

  • 0

First, sorry for the stupid question, but I was reading an article in php.net and I couldn’t understand what exactly it says.

<?php
class SimpleClass
{
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
        echo $this->var;
    }
}
?>



<?php

$instance = new SimpleClass();

$assigned   =  $instance;
$reference  =& $instance;

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null

var_dump($instance);
var_dump($reference);
var_dump($assigned);
?>

And this outputs this:

NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}

$instance and $reference point to same place, I get this and I understand why we get NULL and NULL for them.

But what about $assigned? It’s it also pointing the place where $instance is stored? Why when we use $instance->var it affects $assigned, but when we set $instance to be null, there is no change for $assigned?

I thought that the all three variables point to one place in the memory, but obviously I’m wrong. Could you please explain me what exactly happens and what is $assigned? Thank you very much!

  • 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-13T04:09:20+00:00Added an answer on June 13, 2026 at 4:09 am

    $reference points to the value of $instance, which is itself a reference to an object. So when you change the value contained by $instance, $reference reflects this change.

    $assigned, on the other hand, is a copy of the value of $instance, and independently points to the object itself to which $instance refers. So when the value $instance is updated to point to nothing (i.e. null), $assigned is not affected, since it still points to the object, and doesn’t care about the contents of $instance.

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

Sidebar

Related Questions

first sorry if its a stupid question but im lost a bit. So when
First sorry if its a stupid question but i ran into a problem what
Hello first sorry if its a stupid question, but I amm a beginner, and
First off, sorry if this is a stupid question. I installed code::blocks to try
First of all sorry if it's a dumb question (and surely it is), but
Sorry for the question it might sounds stupid, But: how do you activate a
First of all I am sorry for the stupid question I am going to
First sorry if its a stupid guestion but im a really big beginner. I
First of all I am sorry to ask a stupid question, this is because
I am sorry, my question is stupid, but I am not able to answer

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.