References/copies??

From: Date: Sun, 06 May 2001 05:20:29 +0000
Subject: References/copies??
Groups: php.dev 
Request: Send a blank email to php-dev+get-54068@lists.php.net to get a copy of this message
If I pass a reference to an object and assign that to a class property. Shouldn't the property be a reference back to the original variable's value instead of a copy? Here is some sample code to illustrate my small confusion. <?php class Testie { var $error; function Testie() { } } class Tester { var $testie; function Tester(&$testie) // <-- passing object by reference { $this->testie = $testie; // <--- I must put an & again if I want this to be a reference even though // I already passed a reference } } $t = new Testie(); $a = new Tester(&$t); $a->testie->error = "Hello 123"; $t->error = "GoodBye 123"; print "A::error ".$a->testie->error."\n"; print "T::error $t->error\n"; ?> // with the & A::error GoodBye 123 T::error GoodBye 123 // Without the & A::error Hello 123 T::error GoodBye 123 I suppose this is intended behavior and my laziness is getting the better of me? Chris Newbill OneWest.net Inc., Programmer/Analyst 406.449.8056 cnewbill@onewest.net /* Windows crashed. I am the Blue Screen of Death. No one hears your screams. */

« previous php.dev (#54068) next »