Pretty sure it's not deprecated. I've been doing things like that a lot in PHP 5.3, basically to alias a deeply nested array. For example:
$short = &$a['really']['deep']['array']
When you do $a = $b
and $a
is an object it creates a "reference". This is best illustrated with an example:
>> $o = new stdClass()
stdClass::__set_state(array(
))
>> $o->a = 5
5
>> $o
stdClass::__set_state(array(
'a' => 5,
))
>> $o2 = $o
stdClass::__set_state(array(
'a' => 5,
))
>> $o2->a = 6
6
>> $o
stdClass::__set_state(array(
'a' => 6,
))
Note that both $o->a
and $o2->a
are now 6, even though we only did the assignment on one of them.
When $a
is a primitive (or scalar in PHP) such as string, int or float, it behaves a bit differently; the variable is copied:
>> $a = 1
1
>> $b = $a
1
>> $b = 2
2
>> $a
1
Note that $a
is still 1.
When you use the ampersand, however, it basically works as an alias. Any changes to one variable will effect the other.
>> $c = 1
1
>> $d = &$c
1
>> $d = 2
2
>> $c
2
Note that $c
is also 2 now.