如果我们通过引用传递,是不是创建了变量?

时间:2022-05-06 05:36:27
    $rn = &$vvv;
    echo $vvv;

It gives no error. But this, of course, does:

它没有错误。但是,当然,这样做:

    echo $vvv;

Notice (8): Undefined variable: vvv. Why? Is variable created after we use by reference? That's really strange.

注意(8):未定义的变量:vvv。为什么?在我们使用参考后创建变量?那真的很奇怪。

1 个解决方案

#1


0  

Pretty much yes - variable is created then When you want to get reference to object, PHP will do everything to give you that reference.

几乎是 - 变量被创建然后当你想获得对象的引用时,PHP会尽一切努力为你提供引用。

It simply can't do reference to non-existing variable so it's "setting" NULL first and gives you reference to variable

它根本无法引用不存在的变量,因此它首先“设置”NULL并为您提供变量引用

but what's interesting: isset($vvv) would return correctly false :)

但有趣的是:isset($ vvv)会正确返回false :)

more info: Why php does not complain when referencing a non existing variable?

更多信息:为什么php在引用非现有变量时不会抱怨?

#1


0  

Pretty much yes - variable is created then When you want to get reference to object, PHP will do everything to give you that reference.

几乎是 - 变量被创建然后当你想获得对象的引用时,PHP会尽一切努力为你提供引用。

It simply can't do reference to non-existing variable so it's "setting" NULL first and gives you reference to variable

它根本无法引用不存在的变量,因此它首先“设置”NULL并为您提供变量引用

but what's interesting: isset($vvv) would return correctly false :)

但有趣的是:isset($ vvv)会正确返回false :)

more info: Why php does not complain when referencing a non existing variable?

更多信息:为什么php在引用非现有变量时不会抱怨?