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

The Archive Base Latest Questions

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

I read object references in PHP.I did some experimentation with object references. My doubt

  • 0

I read object references in PHP.I did some experimentation with object references.

My doubt is:

I assigned an object to another variable.Then,I changed the value of variable and print the variable.The both variable get affected.I assigned a object reference to another variable.Then I changed value of variable in one,that affect in both.

 <?php

 ##Class 
 class A
 {
  var $foo = 1;
 }

 #Assignment
 $a = new A();
 $b = $a;

 echo "Assignment:\n";
 $b->foo = 8; 
 echo $a->foo."\n";
 echo $b->foo."\n";

 #Reference
 $c = new A();
 $d =& $c;

 echo "References:\n";
 $d->foo = 4;
 echo $c->foo."\n";
 echo $d->foo."\n";

 ?>

My question is :

What is the difference between assigning an object and assigning an object reference.

Whether the both are same or is there any difference?

  • 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-03T10:41:17+00:00Added an answer on June 3, 2026 at 10:41 am

    What is the difference between assigning an object and assigning an object reference

    PHP does not have object references, so you can not compare against something that does not exist.

    However I assume you want to know the difference between:

    $a = new Foo;
    $b = $a;
    

    and

    $a = new Foo;
    $b = &$a;
    

    The first one is an assignment of the object (which is an object identifier) and the second is making $b an alias of $a. The difference should become clear if we change the flow a bit:

    $a = NULL;
    $b = $a;
    $a = new Foo;
    

    and

    $a = NULL;
    $b = &$a;
    $a = new Foo;
    

    In the first example (assignment), $b is NULL. In the second example, $b is a variable-alias (a.k.a. PHP variable reference).

    After execution, ìn the first example $b is naturally NULL whereas in the second one it is what $a is.

    As you can see, independent to objects, doing an assignment is just not the same as creating a variable reference.

    I hope this clarifies this a bit for you. Don’t talk about references, just talk about variable aliasing. That better matches it in the PHP world.

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

Sidebar

Related Questions

I think I read somewhere that some modules only have object oriented interfaces (
I studied that Java passes object references by value, and in order to make
I have read every where that primitive datatype and object references are passed by
I read that: Object sync = new Object(); /* inter to monitor */ try
I have read about application object in android site but I couldn't understand. What
I've read that using Object.prototype to attach functions to custom JavaScript objects is more
I read about small talk being completely object oriented.. is C++ also completely object
Java - How do you read binary objects into an object array without knowing
Now I am read the book Inside The C++ Object Model 's fourth section
I'm trying to read data from a service (returns JSON object) and create an

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.