| 
	
 | 
 Posted by Chung Leong on 05/19/06 01:36 
rockstar wrote: 
>  The last one, I BELIEVE is creating a reference.  I don't completely 
> understand php references (as my "mentor" of sorts doesn't really 
> either), but I've never had a need to use =&, and it seems to me to be 
> a hack rather than serve a good purpose.  Stick with the middle one, 
> and it'll make everything much cleaner. 
> 
> Paul 
> http://eventuallyanyway.com 
 
In this instance the use of =& is probably useless. There are specific 
situations though where you must use it. Say you have the following: 
 
class Node { 
   var $parent; 
   var $child; 
 
   function Node(&$parent) { 
      $parent->child =& $this; 
   } 
} 
 
$node = new Node($parent); 
 
Because the = operator is assignment by-value, a copy of the new object 
is assigned to $node. Thus $node and $parent->child end up pointing to 
different objects, unlikely to be the desired result.
 
[Back to original message] 
 |