Robert Cummings wrote: ...
Yeah, *grin*. And on that note, there are times when you will actually want $foo = &new SomeClass(); versus $foo = new SomeClass(); since assigning by reference will break any previous references -- something I forgot to mention to Matthew Weier when he challenged the relevance of the snippet I sent. Cheers, Rob.
Indeed... Matt, hope you see this one. I was quite surprised by the results as well!
Rob, since you're explaining this to us now then I assume that the dev team is well aware of this issue and this is intended behavior... or is this something that will be fixed/changed so that we don't have copies of references floating around? Because that seems very unintuitive to me... references to references seems like a better "default" behavior unless there's a good reason why we shouldn't change.
#!/usr/local/bin/php <?php class a { public $changes = 1; function __construct() { $this->changes++; } } class b { } $aObj = new a(); $aRef = &new a(); $bObj = new b(); $foo1 = $aObj; $foo2 = $aObj; $foo3 = $foo1; $foo4 = &$foo2; $foo5 = $aRef; $foo6 = &$aRef; $foo1->changes = 'I changed!'; echo "------------------\n"; print_r( $foo1 ); print_r( $foo2 ); print_r( $foo3 ); print_r( $foo4 ); print_r( $foo5 ); print_r( $foo6 ); $foo1 = $bObj; $foo2 = $bObj; $foo5 = $bObj; echo "------------------\n"; print_r( $foo1 ); print_r( $foo2 ); print_r( $foo3 ); print_r( $foo4 ); print_r( $foo5 ); print_r( $foo6 ); $foo1 = &$aObj; ?> -- NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-general&w=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php