raviolican raviolican - 7 months ago 20
PHP Question

Does a reference to and instance create a new identity

I have

$var1 = 123
$var2 = $var1

Does var2 reference to the identity of the instance 123 or does it copy the instance and creates a new reference in PHP?


$var2 = $var1; does not create a reference. It will indeed be copied.

If you do want a reference, you can do it like this:

$var2 = &$var1;

Further reading