如果我们通过引用传递,是不是创建了变量?
$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在引用非现有变量时不会抱怨?
更多相关文章
- 如果key在变量中,PHP如何从数组中获取值
- 为什么我的变量在TCPDF中没有定义?
- Python:我如何从datetime.timedelta对象中获取时间?
- php如何以一个对象作为数组下标?
- 在SQL中声明@变量返回错误
- MySQL查询中的变量会导致错误
- 如何检查变量是否与fetch()具有相同的值
- php数据库数据转换为js中的json对象
- PHP : mysqli【面向对象】操作数据库【连接、增、删、改、查】