From: Jason Roelofs Date: 2007-09-27T22:53:14+09:00 Subject: Re: Ruby's a = b vs PHP5's $obj1 =& $obj2 ------=_Part_1269_8597765.1190901193857 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/27/07, SpringFlowers AutumnMoon 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. > -- > Posted via http://www.ruby-forum.com/. > > IMO it's giving you a headache because you're trying to compare a clean, well thought out language like Ruby to a hacked-together-over-many-years language like PHP. Ruby acts exactly as you would expect it to. a = Object.new # => a now points to this object a = b # => a and b now point to the same object b = Object.new # => b now points to a new object, a still points to the original object. The faster you stop comparing to PHP and start thinking in terms of how languages are supposed to work, the better. Jason ------=_Part_1269_8597765.1190901193857--