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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC