Cancellation and positioning of php references

伊谢尔伦
Release: 2016-11-22 11:10:37
Original
937 people have browsed it

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);
?>
Copy after login

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"];
?>
Copy after login

This means that, for example, unset $var will not unset a global variable.

$this
Copy after login

In a method of an object, $this is always a reference to the object that calls it.


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!