Re: Bug #1332: Referencing the same object from two variables

From: Date: Tue, 20 Apr 1999 14:04:08 +0000
Subject: Re: Bug #1332: Referencing the same object from two variables
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-5152@lists.php.net to get a copy of this message
On 20 Apr 1999 ursem@albatros.dk wrote: > From: ursem@albatros.dk > Operating system: WinNT > PHP version: 3.0.5 > PHP Bug Type: Other > Bug description: Referencing the same object from two variables > > 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> Why would you expect that? Because you named your variables $ref? :) There are no references of any kind in PHP 3.0, except for a very specific issue of passing by reference. ALL assignments are done by value. > This is very annoying and the whole point of having objects and classes seems to disappear, > except for their "functionality-wrapping" features. As mentioned roughly a zillion times before, the class/object mechanism added to PHP isn't a thorough one, and isn't going to be a thorough one in the future either. It's introduced to allow you to have variable/function namespaces, not in any way make PHP an object oriented language. That said, PHP 4.0 introduces full support for references, but it's still months away before its released. Zeev -- ----------------------------------------------------- Zeev Suraski <zeev@zend.com> For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5152) next »