On 9/27/07, SpringFlowers AutumnMoon <summercoolness / gmail.com> wrote:
> Just want to confirm Ruby's
>
>   a = b
>
> is the same as PHP5's
>
>   $obj1 = $obj2
>
> in other words, the reference is copied.
>
> While
>
>   $obj1 =& $obj2
>
> or
>
>   $obj1 = &$obj2
>
> in both PHP4 and PHP5 isn't the same as Ruby's   a = b
>
> $obj1 and $obj2 just become synonyms...
>
> and after
>
> $obj1 = new Foo("foo1");
> $obj2 =& $obj1
> $obj2 = new Foo("bar1");
>
> $obj1 and $obj2 have the same content, as they are just synonyms. (not a
> clone, not same reference, but just synonyms).  The "foo1" object is
> garbage-collected since no one is referencing it.
>
> this is giving me an initial headache... until maybe after i get used to
> it.

in ruby:

a = Hash.new # a is a reference to Hash object #1
b = a # both a and b point to the same object
a[1] = 'a' # and b[1] is 'a' as well

but

b = Hash.new # now a points to Hash obj #1 and b to #2
b[1] = 'c' # a[1] is still 'a'

i.e. assignment may destroy the link.