Home > Backend Development > PHP Tutorial > PHP引述陷阱

PHP引述陷阱

WBOY
Release: 2016-06-13 13:14:12
Original
1029 people have browsed it

PHP引用陷阱
1.  $a = '333';
    $c = &$a;
    $d = '888';
    $c = &$d;
    echo $c;
    echo $a;

2. $a = '333';
    $c = &$a;
    $d = '888';
    $c = $d;
    echo $c;
    echo $a;

其中第四行$c = $d和$c = &$d,导致的结果完全不一样.
$c = $d,因为$c是$a的一个引用,所以$c和$a的值都会变成888,
但是$c = &$d,是$c变成了$d的引用了,和$a已经没有关系了,所以此时$a的值还是333.
注意,引用只是一个别名而已,并不是指针.
其实类似于Unix的硬连接.
http://www.php.net/manual/zh/language.references.whatare.php

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