PHP References


  • $foo = 1; $bar = &$foo; // both $foo and $bar point to the same value: 1
  • $var = 1; function calc(&$var) { $var *= 15; } calc($var); echo $var;


While assigning two variables by reference, both variables point to the same value. Take the following example:

$foo = 1;
$bar = &$foo;

$foo does not point to $bar. $foo and $bar both point to the same value of $foo, which is 1. To illustrate:

$baz = &$bar;

If we had a points to relationship, this would be broken now after the unset(); instead, $foo and $baz still point to the same value, which is 2.