【发布时间】:2017-02-15 07:29:50
【问题描述】:
我在PHP docs comments 中发现了这条非常古老的评论,但我不明白为什么它在第一个示例中输出“hihaha”而不是“eita”。 $a 已更改,我假设 "hihaha" 已永久删除。如果不是,那为什么如果更改为null 或分配另一个变量的副本,那么"hihaha" 将被永久删除?
// 1. example
$a = "hihaha";
$b = &$a;
$c = "eita";
$a = &$c; // why doesn't this purge "hihaha" from existence?
echo $b; // shows "hihaha" WHY?
// 2. example
$a = "hihaha";
$b = &$a;
$a = null;
echo $b; // shows nothing (both are set to null)
// 3. example
$a = "hihaha";
$b = &$a;
$c = "eita";
$a = $c;
echo $b; // shows "eita"
这是解决循环引用问题的“好方法”吗?
【问题讨论】:
-
因为您已复制参考。因为你踩到了原来的物体。
标签: php reference pass-by-reference