PHP 中 NULL 和 null 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:09:25  来源:igfitidea点击:

Difference between NULL and null in PHP

phpnull

提问by cmcculloh

Is there a difference between NULLand nullin PHP? Sometimes they seem to be interchangeable and sometimes not.

PHP 中的NULL和有区别null吗?有时它们似乎可以互换,有时则不能。

edit: for some reason when I read the documentation linked to in the answer (before posting this question) I read it as "case sensitive" instead of "case insensitive" which was the whole reason I posted this question in the first place...

编辑:出于某种原因,当我阅读答案中链接的文档时(在发布此问题之前),我将其阅读为“区分大小写”而不是“不区分大小写”,这是我首先发布此问题的全部原因。 .

回答by mbillard

Null is case insensitive.

Null 不区分大小写。

From the documentation:

文档

There is only one value of type null, and that is the case-insensitivekeyword NULL.

只有一个 null 类型的值,那就是不区分大小写的关键字 NULL。

回答by SolidSnake

There is no difference. Same type just its a case insensitivekeyword. Same as True/Falseetc...

没有区别。相同类型只是不区分大小写的关键字。与True/False等相同...

回答by David Hahn

well there is a technical difference, just not what you're thinking (think: where does it appear in the dictionary): the ASCII value for lowercase null appears after the upper case. Try:

好吧,存在技术差异,而不是您的想法(想想:它出现在字典中的哪个位置):小写 null 的 ASCII 值出现在大写之后。尝试:

$a = NULL;
$b = null;
if($a < $b){
   print 'first num appears earlier in the dictionary than second num';
}
else {
   print'the right num appears in the dictionary before the left num ';
}

** actually there is no ASCII value for lower case null while upper case NULL is 0. lowercase null would be evaluated as a string value which would be greater than 0. The difference between all upper and lower case ASCII values is 32, except here where an entire string value is considered.

** 实际上没有小写空值的 ASCII 值,而大写空值是 0。小写空值将被评估为一个大于 0 的字符串值。所有大写和小写 ASCII 值之间的差异是 32,除了这里其中考虑了整个字符串值。