views:

107

answers:

4

i wonder where i should put the & properly.

$b =& $a;
or
$b = &$a;
+10  A: 

Both reference the same thing, just a matter of coding style.

Personally, I prefer the $b = &$a style for readability, the space from the & and $ throws me off.

Anthony Forloney
I personally prefer the first way. `$b =`
Blair McMillan
I prefer the second way :)
Anthony Forloney
Aistina
@Aistina, +1, good point to note.
Anthony Forloney
@Aistina very true. Good enough reason to change my preference.
Blair McMillan
A: 

$b = &$a; is better

Adelf
Better how? And in whose opinion? They both do the same thing, "better" is a point of view. -1
Andy E
+1  A: 

This is actually up to you.

I would, like most others, put the & directly before the $ sign of the variable - it makes the code easier to read in my opinion.

lamas
+1  A: 

Put it where the code convention you use tells you to put it.

The PHP manual on references uses =& exclusively, whereas the PHP manual on variables states

To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable).

Gordon