tags:

views:

55

answers:

3
+1  A: 

Passing by value is the normal behavior of PHP. So when you just write $a = $b the value of $b will be assigned to $a.

What you wrote is a reference assignment, declaring $a to be a reference to the variable that is identified by the value of $b (see variable variable).

Gumbo
+2  A: 

While it might be a little hard to follow, your code is perfectly valid and is doing what you want it to do:

$b = 'test';
$test = 100;
$a = &$$b;
echo $a; // displays 100

You are likely getting an error because $b is not set.

evolve
thanks for your answer.
VAC-Prabhu
A: 

Pass by value?

Internally, php always passes by reference. Only when you assign or change the values do php allocate new memory.

For example:

$a = 5;
$b = $a; // this points to the same memory location as a
$a = 2; // now b still points to the same memory location which has 5, but now $a points to a new location with a value of 2

So there is really no need to pass by reference/value. You only need to add the reference indicator (&) when you require that php to assign values to the same memory location and not allocate new memory.

Daniel