这个问题是要注意,以前吃过一次亏 $arr = array(); echo $arr == NULL ;//true echo $arr === NULL;//false 手册提供的信息也不清晰 A variable is considered to be null if: it has been assigned the constant NULL. it has not been set to any value yet. it has been unset(). 貌似要通过读php的C源码探个究竟了.
嗯,我觉得重点是这个 it has not been set to any value yet. $arr = array();//getType($arr) 为 array 和 $arr = "";//getType($arr) 为 string 在解释器看来,可能都属于未设置'值'的情况,即结构体中的value未设置或为null,但是确实容易使人犯错.
写这代码的人无聊~
array的key只是个字符,你喜欢写什么就什么,是字符或正整数就行了
array() 等同于 NULL 么?
隐式转换,NULL被转为了array
$dbginfo['null'] = 'true'; <=== 这个'null'是键名,所以用引号括起
}
关键是,第一句已经给 $dbginfo 赋值 = array() 了。难道 array() == NULL ?
$arr = array();
echo $arr == NULL ;//true
echo $arr === NULL;//false
手册提供的信息也不清晰
A variable is considered to be null if: it has been assigned the constant NULL. it has not been set to any value yet. it has been unset().
貌似要通过读php的C源码探个究竟了.
typedef struct _zval_struct {
zvalue_value value;
zend_uint refcount;
zend_uchar type;
zend_uchar is_ref;
} zval;
怀疑$arr = array();这一句把value设置NULL,type设置为array.
$arr = array();
$str = "";
echo $arr == NULL ? "array == NULL" : "array";
echo $str == NULL ? "string == NULL" : "string";;试了下,两个都是为 true。
it has not been set to any value yet. $arr = array();//getType($arr) 为 array
和
$arr = "";//getType($arr) 为 string
在解释器看来,可能都属于未设置'值'的情况,即结构体中的value未设置或为null,但是确实容易使人犯错.
暂时理解为 php 的 "by-design feature" 好了。谢谢。:)