Friday, February 25, 2011

Pointers in Python resemble variable assignments in PHP5

I encountered the PHP5 clone operator '=&' and a very good illustration of its use. Incidentally, PHP5 variable assignment resembles the use of pointers in Python.

In short, a variable assignment in PHP is a reference to the assignment object. If an object ( $pointer = object ) is reassigned ( object = 'foo'; ), the pointer will reference the OLD object ( $pointer = object ). If however you clone the object ( $clone =& object), when the object is reassigned, ( object = 'foo' ), clone will change as well ( $clone = 'foo' ).

Cloning, then, is making the variable operand synonymous with its counterpart, rather than a reference to the counterpart. There are some particularly enlightening examples of 'clone' aka '=&' on php.net.

No comments: