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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:39:30+00:00 2026-06-05T11:39:30+00:00

<?php class SimpleClass { public $var1; } $instance = new SimpleClass(); $assigned = $instance;

  • 0
<?php
class SimpleClass
{
    public $var1;
}
$instance = new SimpleClass();
$assigned   =  $instance;
$reference  =& $instance;
$instance->var1 = '$assigned will have this value';

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

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

Can any one help? How come the output of above code is:

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

I can understand NULL for $instance and $reference but how come $assigned not became NULL.
As per my understanding in PHP 5 object are pass by reference, so $assigned is also contain reference, in this case it should also become NULL.

In addition to my understanding, written in PHP manual is “When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function. ”

Can any one explain?

  • 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-05T11:39:31+00:00Added an answer on June 5, 2026 at 11:39 am

    Below line are from PHP manual Object and reference

    A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn’t contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.

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

Sidebar

Related Questions

Here is the class: functions.php class buildPage { public function Set($var,$val){ $this->set->$var = $val;
I'm wondering what do we call this kind of assignment. <?php class SimpleClass {
I am new to php, so sorry if this is lame. I have a
I have a php class that tells time like this (Time.class.php): <?PHP class Time
I currently have my PHP class variables set up like this: class someThing {
New to PHP. I have created a simple class: class User { private $name;
I have this PHP class class myclass{ function name($val){ echo this is name method
I have this PHP class, whose purpose is to fetch some configuration data from
I have a PHP Class which requires a unique value in its constructor. If
my action.class.php if ($this->getRequest()->getMethod() == sfRequest::GET) { $this->formShoppingList = new ShoppingListForm(array( 'shoppinglist' => $items,

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.