Whats the difference between =& and &$variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Whats the difference between =& and &$variable

Post by Ambush Commander »

You can:

Code: Select all

$variable  = 'asdf';

$reference1 =& $variable;
$reference2 = &$varable;
And you can also:

Code: Select all

function foo($var) {
   $var = 'bling2';
}

function bar(&$var) {
   $var = 'bling3';
}

$var = 'blinger';

foo(&$var);
bar($var);
bar(&$var);
What's the difference (they all seem to do the same thing)?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

it's all explained here: http://www.php.net/references
Post Reply