PHP: linked list implementation issue with reference to object?
<p>I am creating a linklist class and have some confusion about reference to objects.</p>

<p>As per my understanding by default object is copied by reference. $Obj1 = $Obj2. $Obj1 is a alias of $Obj2.</p>

<p>Can someone please point out which one is correct in linkedlist implementation.</p>

<pre><code>$firstNode-&gt;next = $this-&gt;first;---&gt; seems to be correct
             or 
$firstNode-&gt;next =&amp; $this-&gt;first;

$this-&gt;first = $firstNode;-----&gt; seems to be correct as $firstNode is an object
             or 
$this-&gt;first = &amp; $firstNode;
</code></pre>

<p>code:</p>

<pre><code>class Node {
    public $element;
    public $next;

public function __construct($element){
    $this-&gt;element = $element;
    $this-&gt;next = NULL;
  }
}

class Linklist {

    private $first;
    private $listSize;

 public function __construct(){      
    $this-&gt;first = NULL;
    $this-&gt;listSize = 0;
}

public function InsertToFirst($element){
     $firstNode = new Node($element);
     $firstNode-&gt;next = $this-&gt;first;   // or $firstNode-&gt;next =&amp; $this-&gt;first;
     $this-&gt;first = $firstNode;  // or $this-&gt;first = &amp; $firstNode;
 }
</code></pre>
