php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2755 new Object() scribbles on old references
Submitted: 1999-11-18 16:26 UTC Modified: 1999-11-22 16:58 UTC
From: duncan at emarketeers dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Beta 3 OS: Linux 2.2.9 (RedHat 6.0)
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: duncan at emarketeers dot com
New email:
PHP Version: OS:

 

 [1999-11-18 16:26 UTC] duncan at emarketeers dot com
new Object() does not create a new reference, but writes over the value of an old reference instead.
class Thingy {
  var $instanceVar;
}
$x=new Thingy;
$x->instanceVar=2;
$y=&$x;
$x=new Thingy;
$x->instanceVar=3;

echo $x->instanceVar $y->instanceVar";

prints 3 3 instead of the expected 3 2


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-22 16:58 UTC] zeev at cvs dot php dot net
Your understanding of the semantics is wrong.
When you write:
$y=&$x;
from that point onward, $y and $x are the same thing - nothing can unbind them.  When you assign a new object into
$x, it's identical to assigning the object into $y;  Both
$x and $y will be pointing to the same value, be it a string, an array, or a newly created object.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC