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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 02:01:38 2025 UTC