raviolican raviolican - 1 year ago 65
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?

Answer Source

$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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download