Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does =& mean in PHP?

Tags:

php

Consider:

$smarty =& SESmarty::getInstance(); 

What is the & for?

like image 882
JasonDavis Avatar asked Jan 17 '10 17:01

JasonDavis


1 Answers

It passes by reference. Meaning that it won't create a copy of the value passed.

See: http://php.net/manual/en/language.references.php (See Adam's Answer)

Usually, if you pass something like this:

$a = 5; $b = $a; $b = 3;  echo $a; // 5 echo $b; // 3 

The original variable ($a) won't be modified if you change the second variable ($b) . If you pass by reference:

$a = 5; $b =& $a; $b = 3;  echo $a; // 3 echo $b; // 3 

The original is changed as well.

Which is useless when passing around objects, because they will be passed by reference by default.

like image 130
Tyler Carter Avatar answered Sep 29 '22 10:09

Tyler Carter