What does the PHP operator =& mean?

operators, php

Solution

This isn't an assignment (`=`) by reference (`&`).

If you were to say:

$a = 42;
$b =& $a;

You are actually saying assign `$a` by reference to `$b`.

What assigning by reference does is "tie" the two variables together. Now, if you were to modify `$a` later on, `$b` would change with it.

For example:

$a = 42;
$b =& $a;

//later
echo $a; // 42
echo $b; // 42

$a = 13;
echo $a; // 13
echo $b; // 13

EDIT:

As Artefacto points out in the comments, `$a =& $b` is not the same as `$a = (&$b)`.

This is because while the `&` operator means make a reference out of something, the `=` operator does assign-by-value, so the expression `$a = (&$b)` means make a temporary reference to `$b`, then assign the value of that temporary to `$a`, which is not assign-by-reference.

Problem

Possible Duplicate: What do the "=&" and "&=" operators in PHP mean? I found the operator "=&" in the following code, and I do not know what it means. What does it mean and what does it do? The code where I read it: ``` function ContentParseRoute($segments) { $vars = array(); //Get the active menu item $menu =& JSite::getMenu(); $item =& $menu->getActive(); // Count route segments $count = count($segments); .... ```

Original source

Related problems