Home  >  Article  >  Backend Development  >  Cancellation and positioning of php references

Cancellation and positioning of php references

伊谢尔伦
伊谢尔伦Original
2016-11-22 11:10:37895browse

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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php predefined variablesNext article:php predefined variables