PHP 4.0 Bug #6193: new object makes a shallow copy

From: Date: Wed, 16 Aug 2000 11:28:09 +0000
Subject: PHP 4.0 Bug #6193: new object makes a shallow copy
Groups: php.dev 
Request: Send a blank email to php-dev+get-29113@lists.php.net to get a copy of this message
From: Heinz@chanet.de Operating system: Win2000 PHP version: 4.0.1pl2 PHP Bug Type: Scripting Engine problem Bug description: new object makes a shallow copy The new object function seems to generate the object twice. This is a quite unexpected oo feature and it could be a performance bottleneck for complex classes! test script: <? $register_object; class CTest { var $v; function CTest(&$reg) { $reg= $this; // no difference for: $reg= &$this; } } $myobj= new CTest($register_object); $myobj->v= 1; $register_object->v= 2; echo 'both should be equal: ', $myobj->v, ' ', $register_object->v; ?> I would assume that $myobj and $register_object are the same class instance, but this is not true. Ok, this example is stupid, but assume CTest is a shopping_item and $register_object is a shopping_card. The shopping item in the constructer tries to register itself in the shopping cart. Doesn't this makes sense? In general it's from the SW design point of view critical to handle objects as values and not as refernces. Ok, you introduced in PHP4 the & operator but I've not found how to specify the & operator for the new function. Thanks in advance Heinz

« previous php.dev (#29113) next »