Although this implementation is quite complete, it can't handle function references and some other minor stuff ATM.This function is especially useful if you want to serialize a recursive array by hand.

* Please note the internal behaviour of PHP that seems to do the reference assignment BEFORE actually copying the variable!!! Thus you get an array containing a (different) recursive array for the last testcase, instead of an array containing an empty array as you could expect.

*** WARNING about OBJECTS TRICKY REFERENCES ***-----------------------------------------------The use of references in the context of classesand objects, though well defined in the documentation,is somehow tricky, so one must be very careful whenusing objects. Let's examine the following twoexamples:

$B = $A; // This is not an explicit (=&) reference assignment, // however, $A and $B refer to the same instance // though they are not equivalent names$C =& $A; // Explicit reference assignment, $A and $C refer to // the same instance and they have become equivalent // names of the same instance

Thus, note the difference between assignments $X = $Y and $X =& $Y.When $Y is anything but an object instance, the first assignment meansthat $X will hold an independent copy of $Y, and the second, means that$X and $Y will refer to the same thing, so they are tight together until either $X or $Y is forced to refer to another thing. However, when $Y happens to be an object instance, the semantic of $X = $Y changes and becomes only slightly different to that of $X =& $Y, since in bothcases $X and $Y become references to the same object. See what thisexample outputs:

Although, in general, a formal argument declared as $v in the function 'modify' shown above, impliesthat the actual argument $A, passed when calling the function, is not modified, this is not the case when $A is an object instance. See what theexample code outputs when executed: