Question

Is there a difference between NULL and null in PHP? Sometimes they seem to be interchangeable and sometimes not.

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...

Was it helpful?

Solution

Null is case insensitive.

From the documentation:

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

OTHER TIPS

There is no difference. Same type just its a case insensitive keyword. Same as True/False etc...

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:

$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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top