What does a variable set to “&NULL” means in PHP?

不羁岁月 提交于 2020-01-15 20:30:31

问题


I'm working on a tree structure in PHP. When looping through the nodes, an exception is sometime thrown because some node that should not be null is null, more precisely it's set to "&NULL":

array(13) {
  // ...
  // some data...
  // ...
  ["segments"]=>
  NULL
  ["leaf"]=>
  bool(false)
  ["children"]=>
  &NULL
}

Since it's not inside quotes, I assume it's some kind of special value, but what does it mean?


回答1:


It just means that it is a reference to a value NULL

$a = array();

$n = null;
$a[1] =& $n;

var_dump($a); // array(1) { [1]=> &NULL }

If you change $n = null; to $n = 1; - then you'll get &int(1)




回答2:


It's a reference to a value that is null. "&" is the reference symbol.



来源:https://stackoverflow.com/questions/10792325/what-does-a-variable-set-to-null-means-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!