php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1332 Referencing the same object from two variables
Submitted: 1999-04-20 07:49 UTC Modified: 1999-04-20 15:42 UTC
From: ursem at albatros dot dk Assigned:
Status: Closed Package: Other
PHP Version: 3.0.5 OS: WinNT
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ursem at albatros dot dk
New email:
PHP Version: OS:

 

 [1999-04-20 07:49 UTC] ursem at albatros dot dk
I have experienced "working on a copy"-problem with one object and two variables
  containing the object. Example: (Untested) 

<?
    class someobject
    {
       var $a=4;
     }

     $myobj = new someobject;

     $ref1 = $myobj;
     $ref2 = $myobj;

     $ref2->a = 5;
 ?>

Now ref1 is a someobject where a=4 and ref2 is a someobject where a = 5. I would expect that ref1 and ref2 points to the same object and thus the assignment ref1->a=5 will cause the object referenced by ref1 and ref2 to be updated since it is the same object. <br><br>
This is very annoying and the whole point of having objects and classes seems to disappear, except for their "functionality-wrapping" features.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-04-20 15:42 UTC] andi
References will be supported in PHP 4.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC