Home >Backend Development >PHP Tutorial >Cancellation and positioning of php references
Unreference
When you unset a reference, you just break the binding between the variable name and the variable content. This does not mean that the variable contents are destroyed. For example:
<?php $a = 1; $b =& $a; unset($a); ?>
will not unset $b, just $a.
It may be helpful to compare this with Unix’s unlink call.
Reference positioning
Many PHP syntax structures are implemented through the reference mechanism, so everything mentioned above about reference binding also applies to these structures. Some constructs, such as pass-by-reference and return, have already been mentioned above. Other structures that use references are:
global reference
When you declare a variable with global $var you actually create a reference to the global variable. That is the same as doing:
<?php $var =& $GLOBALS["var"]; ?>
This means that, for example, unset $var will not unset a global variable.
$this
In a method of an object, $this is always a reference to the object that calls it.