php源码学习d7 字符串引用

一、引用不回收

   结论:变量类型一旦成引用,不会回收,一直存在,直到unset或代码运行完毕

$a = 3; // $a type 4 图1
echo $a;
$b = &$a; //$b type 10 $a type 10 图1
echo $b;
echo $a;
$d = $b; // $d type 4
unset($b); // $a type 10 图2
echo $a;
$c = $a; // $c type 4 图2
echo $c;
$a = $a; //$a type 10 图2
echo $a;
$a = $c; //$a type 10 图3
echo $a;
$d = 4; //$d type 4 图3
echo $d;
$a = $d; //$a type 10 图3
echo $a;
$a = 'abcd'; // $a type 10 图4
echo $a;
$a = new stdClass; // $a type 10 图5
echo $d;
$a = function () {
}; // $a type 10 图6
echo $d;
$a = [1, 3]; //$a type 10 图6
echo $d;
$a = null; // $a type 10 图7
echo $d;
unset($a); // $a type 0 图7
echo $d;

图1

图2

图三

图4

图5

图6

图7

二、变量在符号表不回收 

$a = 111;
echo $a;
unset($a);
for ($i=0; $i <1000; $i++) {
    ${"b".$i} = $i;
}
echo $b999;
$a = 222;
echo $a;

三、扩展(引用污染)

$a['test'] = 1; // $a type 7
$b = &$a['test']; // $a type 7 $b type 10
$c = $a; // $c type 7
$c['test'] = 2; 
echo $a['test']; // 结果为2

四、笔记地址

d7 字符串引用

猜你喜欢

转载自blog.csdn.net/smile12393/article/details/88601253